{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cbe775bb-5151-43aa-a36d-d20348b3b774",
   "metadata": {},
   "source": [
    "## LangChain应用\n",
    "\n",
    "### 什么是LangChain\n",
    " > LangChain是一个由语言模型驱动的应用程序开发框架\n",
    "\n",
    "TLDR： LangChain使用AI模型进行工作和构建复杂部分变得更容易，。它通过两种方式帮助实现这一点：\n",
    "\n",
    "1.集成 将外部数据（例如您的文件、其他应用程序和ai数据）带到您的LLM\n",
    "2.代理 允许您的LLM通过决策与其环境进行交互。使用LLM帮助决定下一步要采取什么行动\n",
    "\n",
    "\n",
    "## 为什么选择LangChain\n",
    "1.组件 LangChain可以轻松交互使用语言模型所需的抽象和组件。\n",
    "2.定制链 LangChain提供开箱即用的支持，用于使用和定制“链” 一系列串联在一起的操作。\n",
    "3.速度  这个团队更新速度非常快。您将了解最新的LLM功能。\n",
    "4.社区  很棒的discord和社区支持、聚会、黑客马拉松等。\n",
    "\n",
    "虽然LLM可以很简单（文本输入、文本输出），但一旦您开发出复杂的应用程序，您很快就会遇到LangChain可以帮助您解决的摩擦点\n",
    "\n",
    "## 主要用例\n",
    "- 总结 表达有关文本或聊天交互的最重要的事实\n",
    "- 文档问答  使用文档中的信息回答问题或查询\n",
    "- 提取  从文本或用户查询中提取结构化数据\n",
    "- 评估  了解应用程序输出的质量\n",
    "- 查询表格数据  从数据库或其他表格源中提取数据\n",
    "- 代码理解  推理和消化代码\n",
    "- 与API交互  查询API并与外界交互\n",
    "- 聊天机器人  与用于进行来回交互的框架，结合聊天界面中的记忆\n",
    "- 代理智能体  使用LLM来决定下一步做什么。使用工具实现这些决策。\n",
    "\n",
    "## 作者注\n",
    "- 本手册不会涵盖LangChain的所有方面。其内容经过精心策划，可让您尽快构建和产生影响。\n",
    "- 本笔记本假设您已经在之前的课程了解了LangChain的基础知识。本笔记重点介绍要做什么以及如何应用这些基础知识\n",
    "- 您会注意到我们在整个笔记中重复导入预计。我的目的是倾向于清晰的一面，并帮助您在一个地方看到完整的代码块。无需来回擦好看我们何时导入了包。\n",
    "- 我在整个笔记中使用默认的openai模型。之前的课程中还有另一个关于如何设置其他不同模型的视频。\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "66a00b40-c498-48d2-8946-990888a03021",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "from dotenv import load_dotenv,find_dotenv\n",
    "\n",
    "load_dotenv(find_dotenv())  # 加载 .env 文件中的环境变量\n",
    "\n",
    "api_key = os.environ.get('OPENAI_API_KEY')\n",
    "base_url = os.environ.get('OPENAI_BASE_URL')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "dd5bdad7-19a4-4514-b408-926c841d507f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.container {width:90% !important;}</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 如果要使用显示屏更宽，请运行此单元\n",
    "\n",
    "from IPython.display import display,HTML\n",
    "display(HTML(\"<style>.container {width:90% !important;}</style>\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "151960ee-6902-4926-9164-1842fb6d11d3",
   "metadata": {},
   "source": [
    "## LangChain应用案例\n",
    "\n",
    "### 总结\n",
    "LangChain和LLM最常见的用例之一是总结。您可以总结任何一段文本，但用例涵盖总结通话、文章、书籍、学术论文、法律文件、用户历史记录、表格或财务文件。\n",
    "拥有一个可以快速总结信息的工具非常有帮助。\n",
    "\n",
    "**用例** 总结文章、成绩单、聊天记录、Slack/Discord、客户互动、医疗文件、法律文件、博客、推文主题、代码库、产品评论、财务文件\n",
    "\n",
    "## 短文本摘要\n",
    "对于短文本摘要，方法很简单、事实上，除了简单的提示说明之外，一般不需要做任何花哨的事情\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "adb164e5-dfd6-4227-8cee-927a25b96cc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain import PromptTemplate\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")\n",
    "\n",
    "# 创建我们的模板\n",
    "template =\"\"\"\n",
    "%指示：\n",
    "请总结以下文字，\n",
    "以5岁儿童能理解的方式回答。\n",
    "\n",
    "%文本：\n",
    "{text}\n",
    "\"\"\"\n",
    "\n",
    "# 创建一个 LangChain提示模板稍后我们可以在其中插入值\n",
    "prompt = PromptTemplate(\n",
    "    input_variables=[\"text\"],\n",
    "    template = template,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9b20b17b-8072-43b4-9946-8b2882a00625",
   "metadata": {},
   "outputs": [],
   "source": [
    "confusing_text = \"\"\"\n",
    "在接下来的 130 年里，争论愈演愈烈。\n",
    "一些科学家称 Prototaxites 为地衣，另一些人称其为真菌，还有一些人坚持认为它是一种树。\n",
    "“问题是，当你近距离观察它的解剖结构时，它会让人联想到很多不同的东西，但却无法诊断出任何东西，”地球物理学和进化生物学委员会副教授博伊斯说。\n",
    "“而且它太大了，每当有人说它是什么东西时，其他人都会感到愤怒：‘你怎么会有 20 英尺高的地衣？’”\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5dfe55ac-3d4c-453e-982c-685788910399",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------- 提示开始 -------\n",
      "\n",
      "%指示：\n",
      "请总结以下文字，\n",
      "以5岁儿童能理解的方式回答。\n",
      "\n",
      "%文本：\n",
      "\n",
      "在接下来的 130 年里，争论愈演愈烈。\n",
      "一些科学家称 Prototaxites 为地衣，另一些人称其为真菌，还有一些人坚持认为它是一种树。\n",
      "“问题是，当你近距离观察它的解剖结构时，它会让人联想到很多不同的东西，但却无法诊断出任何东西，”地球物理学和进化生物学委员会副教授博伊斯说。\n",
      "“而且它太大了，每当有人说它是什么东西时，其他人都会感到愤怒：‘你怎么会有 20 英尺高的地衣？’”\n",
      "\n",
      "\n",
      "------- 提示结束 -------\n"
     ]
    }
   ],
   "source": [
    "print (\"------- 提示开始 -------\")\n",
    "\n",
    "final_prompt = prompt.format(text=confusing_text)\n",
    "print(final_prompt)\n",
    "\n",
    "print (\"------- 提示结束 -------\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d0614e55-a3d9-4f68-8332-1916dc642ba4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_17836\\1903654816.py:1: LangChainDeprecationWarning: The method `BaseChatModel.__call__` was deprecated in langchain-core 0.1.7 and will be removed in 1.0. Use invoke instead.\n",
      "  output = llm(final_prompt)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='很久以前，地球上有一种叫做 Prototaxites 的神奇东西。科学家们一直在争论它到底是什么。有些人认为它是像蘑菇一样的东西，有些人觉得它像树，还有些人说它是地衣（一种长在树上的小植物）。但因为它太大了，像一座小山一样，每次有人说它是什么，其他人就会说：“怎么可能有这么大的地衣呢？”所以大家一直在讨论和争论。' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 113, 'prompt_tokens': 171, 'total_tokens': 284, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_ee1d74bde0', 'finish_reason': 'stop', 'logprobs': None} id='run-79592ddc-c8a8-472a-9c8e-24b5b832e021-0' usage_metadata={'input_tokens': 171, 'output_tokens': 113, 'total_tokens': 284}\n"
     ]
    }
   ],
   "source": [
    "output = llm(final_prompt)\n",
    "print (output)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be899ef8-98cf-4966-b555-6e740317fcec",
   "metadata": {},
   "source": [
    "## 结构化提取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "deb4a928-6483-48e8-a158-728b12ba9ddb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain.chains.summarize import load_summarize_chain\n",
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "94b48624-36df-44be-ad1a-111fe1d77446",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一回     靈根育孕源流出　心性修持大道生\n",
      "\n",
      "\n",
      "　　詩曰：\n",
      "　　　　混沌未分天地亂，茫茫渺渺無人見。\n",
      "　　　　自從盤古破鴻濛，開闢從茲清濁辨。\n",
      "　　　　覆載群生仰至仁，發明萬物皆成善。\n",
      "　　　　欲知造化會元功，須看西遊釋厄傳。\n",
      "\n",
      "\n",
      "蓋聞天地之數，有十二萬九千六百歲為一元。將一元分為十二會，乃子、丑、寅\n",
      "、卯、辰、巳、午、未、申、酉、戌、亥之十二支也。每會該一萬八百歲。且就\n",
      "一日而論：子時得陽氣，而丑則雞鳴﹔寅不通光，而卯則日出﹔辰時食後，而巳\n",
      "則挨排﹔日午天中，而未則西蹉﹔申時晡，而日落酉，戌黃昏，而人定亥。譬於\n",
      "大數，若到戌會之終，則天地昏曚而萬物否矣。再去\n"
     ]
    }
   ],
   "source": [
    "with open('./data/xiyouji-part1.txt', 'r', encoding='utf-8') as file:\n",
    "    text = file.read()\n",
    "\n",
    "# 打印前 285 个字符作为预览\n",
    "print (text[:285])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "29590bf4-1602-4539-aa60-2431375a78bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你的文件中有 7792 个token\n"
     ]
    }
   ],
   "source": [
    "num_tokens = llm.get_num_tokens(text)\n",
    "\n",
    "print (f\"你的文件中有 {num_tokens} 个token\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "29d2aa05-8f2a-4410-9f1c-84bcfdfd1cda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你现在有 9 个文档\n"
     ]
    }
   ],
   "source": [
    "text_splitter = RecursiveCharacterTextSplitter(separators=[\"\\n\\n\", \"\\n\"], chunk_size=1000, chunk_overlap=150)\n",
    "docs = text_splitter.create_documents([text])\n",
    "\n",
    "print (f\"你现在有 {len(docs)} 个文档\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8cda0a41-6f20-46cf-b1ba-3079cad73efa",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备好初始化链\n",
    "chain = load_summarize_chain(llm=llm, chain_type='map_reduce', verbose=True) # verbose=True 可选，用于查看发送到 LLM 的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "131a81a9-a213-408f-b999-2c7eb467809b",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_17836\\3541367365.py:2: LangChainDeprecationWarning: The method `Chain.run` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use invoke instead.\n",
      "  output = chain.run(docs)\n",
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n",
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"第一回     靈根育孕源流出　心性修持大道生\n",
      "\n",
      "\n",
      "　　詩曰：\n",
      "　　　　混沌未分天地亂，茫茫渺渺無人見。\n",
      "　　　　自從盤古破鴻濛，開闢從茲清濁辨。\n",
      "　　　　覆載群生仰至仁，發明萬物皆成善。\n",
      "　　　　欲知造化會元功，須看西遊釋厄傳。\n",
      "\n",
      "\n",
      "蓋聞天地之數，有十二萬九千六百歲為一元。將一元分為十二會，乃子、丑、寅\n",
      "、卯、辰、巳、午、未、申、酉、戌、亥之十二支也。每會該一萬八百歲。且就\n",
      "一日而論：子時得陽氣，而丑則雞鳴﹔寅不通光，而卯則日出﹔辰時食後，而巳\n",
      "則挨排﹔日午天中，而未則西蹉﹔申時晡，而日落酉，戌黃昏，而人定亥。譬於\n",
      "大數，若到戌會之終，則天地昏曚而萬物否矣。再去五千四百歲，交亥會之初，\n",
      "則當黑暗，而兩間人物俱無矣，故曰混沌。又五千四百歲，亥會將終，貞下起元\n",
      "，近子之會，而復逐漸開明。邵康節曰：：「冬至子之半，天心無改移。一陽初\n",
      "動處，萬物未生時。」到此，天始有根。再五千四百歲，正當子會，輕清上騰，\n",
      "有日，有月，有星，有辰。日、月、星、辰，謂之四象。故曰，天開於子。又經\n",
      "五千四百歲，子會將終，近丑之會，而逐漸堅實。《易》曰：「大哉乾元！至哉\n",
      "坤元！萬物資生，乃順承天。」至此，地始凝結。再五千四百歲，正當丑會，重\n",
      "濁下凝，有水，有火，有山，有石，有土。水、火、山、石、土，謂之五形。故\n",
      "曰，地闢於丑。又經五千四百歲，丑會終而寅會之初，發生萬物。曆曰：「天氣\n",
      "下降，地氣上升﹔天地交合，群物皆生。」至此，天清地爽，陰陽交合。再五千\n",
      "四百歲，子會將終，近丑之會，而逐漸堅實。《易》曰：「大哉乾元！至哉坤元\n",
      "！萬物資生，乃順承天。」至此，地始凝結。再五千四百歲，正當丑會，重濁下\n",
      "凝，有水，有火，有山，有石，有土。水、火、山、石、土，謂之五形。故曰，\n",
      "地闢於丑。又經五千四百歲，丑會終而寅會之初，發生萬物。曆曰：「天氣下降\n",
      "，地氣上升﹔天地交合，群物皆生。」至此，天清地爽，陰陽交合。再五千四百\n",
      "歲，正當寅會，生人，生獸，生禽，正謂天地人，三才定位。故曰，人生於寅。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"感盤古開闢，三皇治世，五帝定倫，世界之間，遂分為四大部洲：曰東勝神洲，\n",
      "曰西牛賀洲，曰南贍部洲，曰北俱蘆洲。這部書單表東勝神洲。海外有一國土，\n",
      "名曰傲來國。國近大海，海中有一座名山，喚為花果山。此山乃十洲之祖脈，三\n",
      "島之來龍，自開清濁而立，鴻濛判後而成。真個好山！有詞賦為證。賦曰：勢鎮\n",
      "汪洋，威寧瑤海。勢鎮汪洋，潮湧銀山魚入穴﹔威寧瑤海，波翻雪浪蜃離淵。水\n",
      "火方隅高積上，東海之處聳崇巔。丹崖怪石，削壁奇峰。丹崖上，彩鳳雙鳴﹔削\n",
      "壁前，麒麟獨臥。峰頭時聽錦雞鳴，石窟每觀龍出入。林中有壽鹿仙狐，樹上有\n",
      "靈禽玄鶴。瑤草奇花不謝，青松翠柏長春。仙桃常結果，修竹每留雲。一條澗壑\n",
      "籐蘿密，四面原堤草色新。正是百川會處擎天柱，萬劫無移大地根。\n",
      "\n",
      "那座山正當頂上，有一塊仙石。其石有三丈六尺五寸高，有二丈四尺圍圓。三丈\n",
      "六尺五寸高，按周天三百六十五度﹔二丈四尺圍圓，按政曆二十四氣。上有九竅\n",
      "八孔，按九宮八卦。四面更無樹木遮陰，左右倒有芝蘭相襯。\n",
      "\n",
      "蓋自開闢以來，每受天真地秀，日精月華，感之既久，遂有靈通之意。內育仙胞\n",
      "，一日迸裂，產一石卵，似圓毬樣大。因見風，化作一個石猴，五官俱備，四肢\n",
      "皆全。便就學爬學走，拜了四方。目運兩道金光，射沖斗府。驚動高天上聖大慈\n",
      "仁者玉皇大天尊玄穹高上帝，駕座金闕雲宮靈霄寶殿，聚集仙卿，見有金光燄燄\n",
      "，即命千里眼、順風耳開南天門觀看。二將果奉旨出門外，看的真，聽的明。須\n",
      "臾回報道：「臣奉旨觀聽金光之處，乃東勝神洲海東傲來小國之界，有一座花果\n",
      "山，山上有一仙石，石產一卵，見風化一石猴，在那裏拜四方，眼運金光，射沖\n",
      "斗府。如今服餌水食，金光將潛息矣。」玉帝垂賜恩慈曰：「下方之物，乃天地\n",
      "精華所生，不足為異。」\n",
      "\n",
      "那猴在山中，卻會行走跳躍，食草木，飲澗泉，採山花，覓樹果﹔與狼蟲為伴，\n",
      "虎豹為群，獐鹿為友，獼猿為親﹔夜宿石崖之下，朝遊峰洞之中。真是：「山中\n",
      "無甲子，寒盡不知年。」\n",
      "　　一朝天氣炎熱，與群猴避暑，都在松陰之下頑耍。你看他一個個：\n",
      "跳樹攀枝，採花覓果﹔拋彈子，?麼兒﹔跑沙窩，砌寶塔﹔趕蜻蜓，撲蜡﹔參老\n",
      "天，拜菩薩﹔扯葛籐，編草﹔捉虱子，咬又掐﹔理毛衣，剔指甲。挨的挨，擦的\n",
      "擦﹔推的推，壓的壓﹔扯的扯，拉的拉：青松林下任他頑，綠水澗邊隨洗濯。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"一群猴子耍了一會，卻去那山澗中洗澡。見那股澗水奔流，真個似滾瓜湧濺。古\n",
      "云：「禽有禽言，獸有獸語。」眾猴都道：「這股水不知是那裏的水。我們今日\n",
      "趕閑無事，順澗邊往上溜頭尋看源流，耍子去耶！」喊一聲，都拖男挈女，呼弟\n",
      "呼兄，一齊跑來，順澗爬山，直至源流之處，乃是一股瀑布飛泉。但見那：\n",
      "一派白虹起，千尋雪浪飛。\n",
      "　　　　海風吹不斷，江月照還依。\n",
      "　　　　冷氣分青嶂，餘流潤翠微。\n",
      "　　　　潺湲名瀑布，真似掛簾帷。\n",
      "\n",
      "眾猴拍手稱揚道：「好水，好水！原來此處遠通山腳之下，直接大海之波。」又\n",
      "道：「那一個有本事的，鑽進去尋個源頭出來，不傷身體者，我等即拜他為王。」\n",
      "連呼了三聲，忽見叢雜中跳出一個石猴，應聲高叫道：「我進去，我進去。」好\n",
      "猴！也是他：\n",
      "        今日芳名顯，時來大運通。\n",
      "　　　　有緣居此地，王遣入仙宮。\n",
      "\n",
      "你看他瞑目蹲身，將身一縱，徑跳入瀑布泉中，忽睜睛抬頭觀看，那裏邊卻無水\n",
      "無波，明明朗朗的一架橋梁。他住了身，定了神，仔細再看，原來是座鐵板橋。\n",
      "橋下之水，沖貫於石竅之間，倒掛流出去，遮閉了橋門。卻又欠身上橋頭，再走\n",
      "再看，卻似有人家住處一般，真個好所在。但見那：\n",
      "\n",
      "翠蘚堆藍，白雲浮玉，光搖片片煙霞。虛窗靜室，滑凳板生花。乳窟龍珠倚掛，\n",
      "縈迴滿地奇葩。鍋灶傍崖存火跡，樽罍靠案見殽渣。石座石床真可愛，石盆石碗\n",
      "更堪誇。又見那一竿兩竿修竹，三點五點梅花。幾樹青松常帶雨，渾然像個人家。\n",
      "\n",
      "看罷多時，跳過橋中間，左右觀看。只見正當中有一石碣，碣上有一行楷書大字\n",
      "，鐫著「花果山福地，水簾洞洞天」。\n",
      "\n",
      "石猿喜不自勝，急抽身往外便走，復瞑目蹲身，跳出水外，打了兩個呵呵道：\n",
      "「大造化！大造化！」眾猴把他圍住，問道：「裏面怎麼樣？水有多深？」石猴\n",
      "道：「沒水！沒水！原來是一座鐵板橋，橋那邊是一座天造地設的家當。」眾猴\n",
      "道：「怎見得是個家當？」石猴笑道：「這股水乃是橋下沖貫石橋，倒掛下來遮\n",
      "閉門戶的。橋邊有花有樹，乃是一座石房。房內有石窩、石灶、石碗、石盆、石\n",
      "床、石凳。中間一塊石碣上，鐫著『花果山福地，水簾洞洞天』。真個是我們安\n",
      "身之處。裏面且是寬闊，容得千百口老小。\n",
      "我們都進去住，也省得受老天之氣。這裏邊：\n",
      "　　　　刮風有處躲，下雨好存身。\n",
      "　　　　霜雪全無懼，雷聲永不聞。\n",
      "　　　　煙霞常照耀，祥瑞每蒸熏。\n",
      "　　　　松竹年年秀，奇花日日新。」\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"眾猴聽得，個個歡喜。都道：「你還先走，帶我們進去，進去。」石猴卻又瞑目\n",
      "蹲身，往裏一跳，叫道：「都隨我進來，進來。」那些猴有膽大的，都跳進去了\n",
      "﹔膽小的，一個個伸頭縮頸，抓耳撓腮，大聲叫喊，纏一會，也都進去了。跳過\n",
      "橋頭，一個個搶盆奪碗，佔灶爭床，搬過來，移過去，正是猴性頑劣，再無一個\n",
      "寧時，只搬得力倦神疲方止。石猿端坐上面道：「列位呵，『人而無信，不知其\n",
      "可。』你們才說有本事進得來，出得去，不傷身體者，就拜他為王。我如今進來\n",
      "又出去，出去又進來，尋了這一個洞天與列位安眠穩睡，各享成家之福，何不拜\n",
      "我為王？」眾猴聽說，即拱伏無違，一個個序齒排班，朝上禮拜，都稱「千歲大\n",
      "王」。自此，石猿高登王位，將「石」字兒隱了，遂稱「美猴王」。有詩為證。\n",
      "詩曰：\n",
      "　　　　三陽交泰產群生，仙石胞含日月精。\n",
      "　　　　借卵化猴完大道，假他名姓配丹成。\n",
      "　　　　內觀不識因無相，外合明知作有形。\n",
      "　　　　歷代人人皆屬此，稱王稱聖任縱橫。\n",
      "\n",
      "美猴王領一群猿猴、獼猴、馬猴等，分派了君臣佐使。朝遊花果山，暮宿水簾洞\n",
      "，合契同情，不入飛鳥之叢，不從走獸之類，獨自為王，不勝歡樂。是以：\n",
      "　　　　春採百花為飲食，夏尋諸果作生涯。\n",
      "　　　　秋收芋栗延時節，冬覓黃精度歲華。\n",
      "\n",
      "美猴王享樂天真，何期有三五百載。一日，與群猴喜宴之間，忽然憂惱，墮下淚\n",
      "來。眾猴慌忙羅拜道：「大王何為煩惱？」猴王道：「我雖在歡喜之時，卻有一\n",
      "點兒遠慮，故此煩惱。」眾猴又笑道：「大王好不知足。我等日日歡會，在仙山\n",
      "福地，古洞神洲，不伏麒麟轄，不伏鳳凰管，又不伏人間王位所拘束，自由自在\n",
      "，乃無量之福，為何遠慮而憂也？」猴王道：「今日雖不歸人王法律，不懼禽獸\n",
      "威嚴，將來年老血衰，暗中有閻王老子管著，一旦身亡，可不枉生世界之中，不\n",
      "得久注天人之內？」眾猴聞此言，一個個掩面悲啼，俱以無常為慮。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"只見那班部中，忽跳出一個通背猿猴，厲聲高叫道：「大王若是這般遠慮，真所\n",
      "謂道心開發也。如今五蟲之內，惟有三等名色不伏閻王老子所管。」猴王道：\n",
      "「你知那三等人？」猿猴道：「乃是佛與仙與神聖三者，躲過輪迴，不生不滅，\n",
      "與天地山川齊壽。」猴王道：「此三者居於何所？」猿猴道：「他只在閻浮世界\n",
      "之中，古洞仙山之內。」猴王聞之，滿心歡喜道：「我明日就辭汝等下山，雲遊\n",
      "海角，遠涉天涯，務必訪此三者，學一個不老長生，常躲過閻君之難。」噫！這\n",
      "句話，頓教跳出輪迴網，致使齊天大聖成。眾猴鼓掌稱揚，都道：「善哉，善哉\n",
      "！我等明日越嶺登山，廣尋些果品，大設筵宴送大王也。」\n",
      "　　次日，眾猴果去採仙桃，摘異果，刨山藥，斸黃精。芝蘭香蕙，瑤草奇花，\n",
      "般般件件，整整齊齊，擺開石凳石桌，排列仙酒仙殽。但見那：\n",
      "金丸珠彈，紅綻黃肥。金丸珠彈臘櫻桃，色真甘美﹔紅綻黃肥熟梅子，味果香酸\n",
      "。鮮龍眼，肉甜皮薄﹔火荔枝，核小囊紅。林檎碧實連枝獻，枇杷緗苞帶葉擎。\n",
      "兔頭梨子雞心棗，消渴除煩更解酲。香桃爛杏，美甘甘似玉液瓊漿﹔脆李楊梅，\n",
      "酸蔭蔭如脂酥膏酪。紅囊黑子熟西瓜，四瓣黃皮大柿子。石榴裂破，丹砂粒現火\n",
      "晶珠﹔芋栗剖開，堅硬肉團金瑪瑙。胡桃銀杏可傳茶，椰子葡萄能做酒。榛松榧\n",
      "柰滿盤盛，橘蔗柑橙盈案擺。熟煨山藥，爛煮黃精。搗碎茯苓並薏苡，石鍋微火\n",
      "漫炊羹。人間縱有珍饈味，怎比山猴樂更寧。\n",
      "\n",
      "群猴尊美猴王上坐，各依齒肩排於下邊，一個個輪流上前奉酒、奉花、奉果，痛\n",
      "飲了一日。\n",
      "\n",
      "次日，美猴王早起，教：「小的們，替我折些枯松，編作?子，取個竹竿作篙，\n",
      "收拾些果品之類，我將去也。」果獨自登?，儘力撐開，飄飄蕩蕩，徑向大海波\n",
      "中，趁天風，來渡南贍部洲地界。這一去，正是那：\n",
      "        天產仙猴道行隆，離山駕?趁天風。\n",
      "　　　　飄洋過海尋仙道，立志潛心建大功。\n",
      "　　　　有分有緣休俗願，無憂無慮會元龍。\n",
      "　　　　料應必遇知音者，說破源流萬法通。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"也是他運至時來，自登木?之後，連日東南風緊，將他送到西北岸前，乃是南贍\n",
      "部洲地界。持篙試水，偶得淺水，棄了?子，跳上岸來。只見海邊有人捕魚、打\n",
      "雁、穵蛤、淘鹽。他走近前，弄個把戲，妝個虎，嚇得那些人丟筐棄網，四散奔\n",
      "跑。將那跑不動的拿住一個，剝了他衣裳，也學人穿在身上。搖搖擺擺，穿州過\n",
      "府，在市廛中學人禮，學人話。朝餐夜宿，一心裏訪問佛、仙、神聖之道，覓個\n",
      "長生不老之方。見世人都是為名為利之徒，更無一個為身命者。正是那：\n",
      "　　　　爭名奪利幾時休？早起遲眠不自由！\n",
      "　　　　騎著驢騾思駿馬，官居宰相望王侯。\n",
      "　　　　只愁衣食耽勞碌，何怕閻君就取勾。\n",
      "　　　　繼子蔭孫圖富貴，更無一個肯回頭。\n",
      "\n",
      "猴王參訪仙道，無緣得遇。在於南贍部洲，串長城，遊小縣，不覺八九年餘。忽\n",
      "行至西洋大海，他想著海外必有神仙。獨自個依前作?，又飄過西海，直至西牛\n",
      "賀洲地界。登岸遍訪多時，忽見一座高山秀麗，林麓幽深。他也不怕狼蟲，不懼\n",
      "虎豹，登上山頂上觀看。果是好山：\n",
      "千峰排戟，萬仞開屏。日映嵐光輕鎖翠，雨收黛色冷含青。瘦籐纏老樹，古渡界\n",
      "幽程。奇花瑞草，修竹喬松。修竹喬松，萬載常青欺福地﹔奇花瑞草，四時不謝\n",
      "賽蓬瀛。幽鳥啼聲近，源泉響溜清。重重谷壑芝蘭繞，處處巉崖苔蘚生。起伏巒\n",
      "頭龍脈好，必有高人隱姓名。\n",
      "\n",
      "正觀看間，忽聞得林深之處有人言語。急忙趨步，穿入林中，側耳而聽，原來是\n",
      "歌唱之聲。歌曰：\n",
      "「觀棋柯爛，伐木丁丁，雲邊谷口徐行。賣薪沽酒，狂笑自陶情。蒼逕秋高，對\n",
      "月枕松根，一覺天明。認舊林，登崖過嶺，持斧斷枯籐。收來成一擔，行歌市上\n",
      "，易米三升。更無些子爭競，時價平平。不會機謀巧算，沒榮辱，恬淡延生。相\n",
      "逢處，非仙即道，靜坐講黃庭。」\n",
      "\n",
      "美猴王聽得此言，滿心歡喜道：「神仙原來藏在這裏！」即忙跳入裏面，仔細再\n",
      "看，乃是一個樵子，在那裏舉斧砍柴。但看他打扮非常：\n",
      "\n",
      "頭上戴箬笠，乃是新筍初脫之籜。身上穿布衣，乃是木綿撚就之紗。腰間繫環絛\n",
      "，乃是老蠶口吐之絲。足下踏草履，乃是枯莎槎就之爽。手執?鋼斧，擔挽火麻\n",
      "繩。扳松劈枯樹，爭似此樵能。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"頭上戴箬笠，乃是新筍初脫之籜。身上穿布衣，乃是木綿撚就之紗。腰間繫環絛\n",
      "，乃是老蠶口吐之絲。足下踏草履，乃是枯莎槎就之爽。手執?鋼斧，擔挽火麻\n",
      "繩。扳松劈枯樹，爭似此樵能。\n",
      "\n",
      "猴王近前叫道：「老神仙，弟子起手。」那樵漢慌忙丟了斧，轉身答禮道：「不\n",
      "當人，不當人。我拙漢衣食不全，怎敢當『神仙』二字？」猴王道：「你不是神\n",
      "仙，如何說出神仙的話來？」樵夫道：「我說甚麼神仙話？」猴王道：「我才來\n",
      "至林邊，只聽的你說：『相逢處，非仙即道，靜坐講《黃庭》。』《黃庭》乃道\n",
      "德真言，非神仙而何？」樵夫笑道：「實不瞞你說，這個詞名做《滿庭芳》，乃\n",
      "一神仙教我的。那神仙與我舍下相鄰，他見我家事勞苦，日常煩惱，教我遇煩惱\n",
      "時，即把這詞兒念念，一則散心，二則解困。我才有些不足處思慮，故此念念，\n",
      "不期被你聽了。」猴王道：「你家既與神仙相鄰，何不從他修行？學得個不老之\n",
      "方，卻不是好？」樵夫道：「我一生命苦：自幼蒙父母養育至八九歲，才知人事\n",
      "，不幸父喪，母親居孀。再無兄弟姊妹，只我一人，沒奈何，早晚侍奉。如今母\n",
      "老，一發不敢拋離。卻又田園荒蕪，衣食不足，只得斫兩束柴薪，挑向市廛之間\n",
      "，貨幾文錢，糴幾升米，自炊自造，安排些茶飯，供養老母。所以不能修行。」\n",
      "\n",
      "猴王道：「據你說起來，乃是一個行孝的君子，向後必有好處。但望你指與我那\n",
      "神仙住處，卻好拜訪去也。」樵夫道：「不遠，不遠。此山叫做靈臺方寸山，山\n",
      "中有座斜月三星洞，那洞中有一個神仙，稱名須菩提祖師。那祖師出去的徒弟，\n",
      "也不計其數，見今還有三四十人從他修行。你順那條小路兒，向南行七八里遠近\n",
      "，即是他家了。」猴王用手扯住樵夫道：「老兄，你便同我去去，若還得了好處\n",
      "，決不忘你指引之恩。」樵夫道：「你這漢子甚不通變，我方才這般與你說了，\n",
      "你還不省？假若我與你去了，卻不誤了我的生意？老母何人奉養？我要斫柴，你\n",
      "自去，自去。」\n",
      "\n",
      "猴王聽說，只得相辭。出深林，找上路徑，過一山坡，約有七八里遠，果然望見\n",
      "一座洞府。挺身觀看，真好去處！但見：\n",
      "煙霞散彩，日月搖光。千株老柏，萬節修篁。千株老柏，帶雨半空青冉冉﹔萬節\n",
      "修篁，含煙一壑色蒼蒼。門外奇花佈錦，橋邊瑤草噴香。石崖突兀青苔潤，懸壁\n",
      "高張翠蘚長。時聞仙鶴唳，每見鳳凰翔。仙鶴唳時，聲振九皋霄漢遠﹔鳳凰翔起\n",
      "，翎毛五色彩雲光。玄猿白鹿隨隱見，金獅玉象任行藏。細觀靈福地，真個賽天\n",
      "堂。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"又見那洞門緊閉，靜悄悄杳無人跡。忽回頭，見崖頭立一石碑，約有三丈餘高，\n",
      "八尺餘闊，上有一行十個大字，乃是「靈臺方寸山，斜月三星洞」。美猴王十分\n",
      "歡喜道：「此間人果是樸實，果有此山此洞。」看勾多時，不敢敲門。且去跳上\n",
      "松枝梢頭，摘松子吃了頑耍。\n",
      "\n",
      "少頃間，只聽得呀的一聲，洞門開處，裏面走出一個仙童，真個丰姿英偉，像貌\n",
      "清奇，比尋常俗子不同。但見他：\n",
      "　　　　髽髻雙絲綰，寬袍兩袖風。\n",
      "　　　　貌和身自別，心與相俱空。\n",
      "　　　　物外長年客，山中永壽童。\n",
      "　　　　一塵全不染，甲子任翻騰。\n",
      "\n",
      "那童子出得門來，高叫道：「甚麼人在此搔擾？」猴王撲的跳下樹來，上前躬身\n",
      "道：「仙童，我是個訪道學仙之弟子，更不敢在此搔擾。」仙童笑道：「你是個\n",
      "訪道的麼？」猴王道：「是。」童子道：「我家師父正才下榻，登壇講道，還未\n",
      "說出原由，就教我出來開門。說：『外面有個修行的來了，可去接待接待。』想\n",
      "必就是你了？」猴王笑道：「是我，是我。」童子道：「你跟我進來。」\n",
      "\n",
      "這猴王整衣端肅，隨童子徑入洞天深處觀看：一層層深閣瓊樓，一進進珠宮貝闕\n",
      "，說不盡那靜室幽居。直至瑤臺之下，見那菩提祖師端坐在臺上，兩邊有三十個\n",
      "小仙侍立臺下。果然是：\n",
      "大覺金仙沒垢姿，西方妙相祖菩提。不生不滅三三行，全氣全神萬萬慈。空寂自\n",
      "然隨變化，真如本性任為之。與天同壽莊嚴體，歷劫明心大法師。\n",
      "\n",
      "美猴王一見，倒身下拜，磕頭不計其數，口中只道：「師父，師父，我弟子志心\n",
      "朝禮，志心朝禮。」祖師道：「你是那方人氏？且說個鄉貫、姓名明白，再拜。」\n",
      "猴王道：「弟子乃東勝神洲傲來國花果山水簾洞人氏。」祖師喝令：「趕出去！\n",
      "他本是個撒詐搗虛之徒，那裏修甚麼道果！」猴王慌忙磕頭不住道：「弟子是老\n",
      "實之言，決無虛詐。」祖師道：「你既老實，怎麼說東勝神洲？那去處到我這裏\n",
      "隔兩重大海，一座南贍部洲，如何就得到此？」猴王叩頭道：「弟子飄洋過海，\n",
      "登界遊方，有十數個年頭，方才訪到此處。」\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"祖師道：「既是逐漸行來的也罷。你姓甚麼？」猴王又道：「我無性。人若罵我\n",
      "，我也不惱﹔若打我，我也不嗔。只是陪個禮兒就罷了。一生無性。」祖師道：\n",
      "「不是這個性。你父母原來姓甚麼？」猴王道：「我也無父母。」祖師道：「既\n",
      "無父母，想是樹上生的？」猴王道：「我雖不是樹上生，卻是石裏長的。我只記\n",
      "得花果山上有一塊仙石，其年石破，我便生也。」祖師聞言暗喜，道：「這等說\n",
      "，卻是個天地生成的。你起來走走我看。」猴王縱身跳起，拐呀拐的走了兩遍。\n",
      "祖師笑道：「你身軀雖是鄙陋，卻像個食松果的猢猻。我與你就身上取個姓氏，\n",
      "意思教你姓『猢』。猢字去了個獸傍，乃是個古月。古者，老也﹔月者，陰也。\n",
      "老陰不能化育，教你姓『猻』倒好。猻字去了獸傍，乃是個子系。子者，兒男也﹔\n",
      "系者。嬰細也，正合嬰兒之本論。教你姓『孫』罷。」猴王聽說，滿心歡喜，朝\n",
      "上叩頭道：「好！好！好！今日方知姓也。萬望師父慈悲，既然有姓，再乞賜個\n",
      "名字，卻好呼喚。」祖師道：「我門中有十二個字，分派起名，到你乃第十輩之\n",
      "小徒矣。」猴王道：「那十二個字？」祖師道：「乃廣、大、智、慧、真、如、\n",
      "性、海、穎、悟、圓、覺十二字。排到你，正當『悟』字。與你起個法名叫做\n",
      "『孫悟空』，好麼？」猴王笑道：「好！好！好！自今就叫做孫悟空也。」正是：\n",
      "    鴻濛初闢原無姓，打破頑空須悟空。\n",
      "　　畢竟不知向後修些甚麼道果，且聽下回分解。\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:360: UserWarning: Unexpected type for token usage: <class 'NoneType'>\n",
      "  warnings.warn(f\"Unexpected type for token usage: {type(new_usage)}\")\n",
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"The text describes the cyclical nature of the universe, where a complete cycle spans 129,600 years, divided into twelve segments corresponding to the twelve Chinese zodiac signs. Each segment lasts 10,800 years, marking different phases in the cosmic order. It begins with chaotic darkness, progresses to the creation of celestial bodies, and continues with the formation of earth and life, culminating in human existence. The narrative emphasizes the interplay of yin and yang, illustrating the emergence of order from chaos and the birth of all things through cosmic cycles.\n",
      "\n",
      "The excerpt describes the mythical origins and geography of a world divided into four continents, focusing on the \"Eastern Victory Divine Continent.\" Within this continent lies the mystical \"Aolai Country,\" near which stands the \"Flower Fruit Mountain,\" a place of extraordinary beauty and significance. At the mountain's peak is a magical stone that absorbs celestial energies over time, eventually producing a stone egg that hatches into a stone monkey. This monkey possesses remarkable qualities, such as emitting golden light from its eyes, which draws the attention of celestial beings. Despite the curiosity it incites, the monkey lives harmoniously in the mountain, forming bonds with various animals and enjoying a carefree life among nature.\n",
      "\n",
      "A group of monkeys, seeking adventure, decide to follow a mountain stream to its source. They discover a magnificent waterfall and challenge each other to find its origin. A stone monkey steps up, jumps into the waterfall, and discovers a hidden paradise behind it—a cave with a bridge and a natural stone dwelling, labeled as \"Flower Fruit Mountain Blessed Land, Water Curtain Cave Celestial Realm.\" Excited by the discovery, the stone monkey returns to share the news, suggesting they all move into this sheltered and idyllic place, away from the harsh elements of nature.\n",
      "\n",
      "A group of monkeys, led by the Stone Monkey, explore a cave and are impressed by the Stone Monkey's ability to lead them safely in and out. As a result, they proclaim him their king, giving him the title \"Monkey King.\" The Monkey King enjoys a carefree life with the other monkeys on Flower Fruit Mountain, indulging in the natural bounty of the changing seasons. However, during a feast, the Monkey King becomes troubled by the inevitability of aging and death, expressing concern about being subject to the rule of the King of Hell when he dies. This realization causes all the monkeys to worry about the impermanence of life.\n",
      "\n",
      "A group of monkeys, led by their king, learns about three beings—Buddhas, immortals, and sages—who escape the cycle of reincarnation and enjoy eternal life. Inspired by this, the Monkey King decides to embark on a journey to seek these beings and learn the secret of immortality. The monkeys celebrate his decision by gathering fruits and preparing a feast. The next day, the Monkey King sets off alone, constructing a raft to sail across the ocean, determined to find enlightenment and achieve great deeds.\n",
      "\n",
      "The Monkey King arrives at the southern continent, startling people by pretending to be a tiger to acquire clothes. He travels through towns and villages for eight to nine years, seeking enlightenment and immortality, but finds people are mostly concerned with fame and wealth. Eventually, he ventures to the western continent, believing it to be home to deities. He discovers a beautiful mountain and hears singing, realizing that immortals might be present. The singing comes from a woodcutter, whom the Monkey King suspects is an immortal due to his simple yet content lifestyle.\n",
      "\n",
      "The passage describes a conversation between the Monkey King and a humble woodcutter. The woodcutter, wearing simple attire, is mistaken for a sage by the Monkey King due to his recitation of a calming verse taught by a neighboring immortal. The woodcutter explains his modest lifestyle, dedicating himself to caring for his elderly mother, which prevents him from pursuing spiritual practices. He directs the Monkey King to the immortal's residence, the Cave of Slanting Moon and Three Stars, on Spirit Platform Mountain. The Monkey King ventures to the cave, marveling at its picturesque, mystical surroundings, and is eager to meet the immortal, Subhuti.\n",
      "\n",
      "The Monkey King arrives at the closed door of a mystical cave, feeling excited upon confirming the existence of the Ling Tai Fang Cun Mountain and Xie Yue San Xing Cave. He hesitates to knock, instead playing in the trees. Soon, a celestial child emerges, questioning the disturbance. The Monkey King explains he is a disciple seeking enlightenment. The child invites him inside, leading him through magnificent structures to the Bodhi Patriarch. The Monkey King humbly greets the Patriarch, but is initially dismissed as deceitful. He insists on his sincerity, explaining he traveled across vast oceans for years to reach this place.\n",
      "\n",
      "In this passage, the Monkey King encounters a master who asks for his surname. The Monkey King explains that he has no surname, as he was born from a stone on Flower-Fruit Mountain and has no parents. The master, recognizing the Monkey King's unique origin as a creation of heaven and earth, decides to give him a surname and name. He derives the surname \"Sun\" (孫) from wordplay involving Chinese characters, and names him \"Sun Wukong\" (孫悟空), fitting the \"Wu\" (悟) generation of disciples. The Monkey King is delighted with his new name, marking a new chapter in his life.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "The text explores the cyclical nature of the universe, with a complete cycle spanning 129,600 years, divided into twelve segments aligned with the Chinese zodiac signs. Each segment lasts 10,800 years, marking phases from chaos to human existence, emphasizing the interplay of yin and yang. It introduces a mythical world of four continents, focusing on the Eastern Victory Divine Continent and the mystical Aolai Country. Here, a magical stone on Flower Fruit Mountain eventually produces a stone monkey, who becomes the Monkey King after discovering a hidden paradise behind a waterfall.\n",
      "\n",
      "The Monkey King enjoys a carefree life but becomes troubled by mortality, prompting him to seek immortality. He embarks on a journey across continents, encountering a humble woodcutter who directs him to the immortal Subhuti's residence. There, the Monkey King insists on his sincerity to learn enlightenment. The master recognizes his unique origin and names him Sun Wukong, marking a new chapter in his life.\n"
     ]
    }
   ],
   "source": [
    "# 使用它。这将遍历 9 个文档，总结块，然后获得摘要的摘要。\n",
    "output = chain.run(docs)\n",
    "print (output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5243230b-9e4e-42c1-b9be-47b872029714",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2ff2fc5c-0d53-449d-9174-91aca2263698",
   "metadata": {},
   "outputs": [],
   "source": [
    "context = \"\"\"\n",
    "小明 30 岁\n",
    "小军 45 岁\n",
    "小文 65 岁\n",
    "\"\"\"\n",
    "\n",
    "question = \"谁40岁以下?\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d411ead0-aaeb-4f0d-942c-11eed8e760f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='根据你提供的信息，只有小明是40岁以下的。小军和小文的年龄都超过了40岁。' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 33, 'total_tokens': 61, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_ee1d74bde0', 'finish_reason': 'stop', 'logprobs': None} id='run-011800dd-196c-45a0-a536-d8f066c8dbb1-0' usage_metadata={'input_tokens': 33, 'output_tokens': 28, 'total_tokens': 61}\n"
     ]
    }
   ],
   "source": [
    "output = llm(context + question)\n",
    "\n",
    "print (output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "43366828-39d7-4e27-884e-effa09343070",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 我们将使用的向量存储\n",
    "from langchain.vectorstores import FAISS\n",
    "\n",
    "# 我们将用来获取文档的 LangChain 组件\n",
    "from langchain.chains import RetrievalQA\n",
    "\n",
    "# 简单的文本文档加载器\n",
    "from langchain.document_loaders import TextLoader\n",
    "\n",
    "# 将文本转换为向量的嵌入引擎\n",
    "from langchain.embeddings.openai import OpenAIEmbeddings\n",
    "\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "6526c0f6-8f4e-4fb8-aae0-d7fd493a16d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你有 1 个文档\n",
      "你有 7516 字符在这个文档中\n"
     ]
    }
   ],
   "source": [
    "loader = TextLoader('./data/xiyouji-part1.txt',encoding=\"utf-8\")\n",
    "doc = loader.load()\n",
    "print (f\"你有 {len(doc)} 个文档\")\n",
    "print (f\"你有 {len(doc[0].page_content)} 字符在这个文档中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "af2ecf5f-5a52-4316-b60d-252e2b9e82cc",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "\n",
    "text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)\n",
    "docs = text_splitter.split_documents(doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "85e3826d-67b1-41c0-ba8c-d6fca66a9906",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "现在你有 9 个文档，平均每个文档有 877 个字符\n"
     ]
    }
   ],
   "source": [
    "# 获取字符总数，以便我们稍后查看平均值\n",
    "num_total_characters = sum([len(x.page_content) for x in docs])\n",
    "\n",
    "print(f\"现在你有 {len(docs)} 个文档，平均每个文档有 {num_total_characters / len(docs):,.0f} 个字符\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "fa22354e-4f5b-4f0a-a5dd-e6fe1189db75",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_17836\\608587630.py:2: LangChainDeprecationWarning: The class `OpenAIEmbeddings` was deprecated in LangChain 0.0.9 and will be removed in 1.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAIEmbeddings`.\n",
      "  embeddings = OpenAIEmbeddings()\n"
     ]
    }
   ],
   "source": [
    "# 准备好你的嵌入引擎\n",
    "embeddings = OpenAIEmbeddings()\n",
    "\n",
    "# 嵌入你的文档并与原始文本结合到一个伪数据库中。注意：这将向 OpenAI 发出一个 API 调用\n",
    "docsearch = FAISS.from_documents(docs, embeddings)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "525d5ed9-bca0-422c-a49c-a27c678026e5",
   "metadata": {},
   "source": [
    "创建您的检索引擎"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "410ae96b-e42b-46e6-9f43-e807f9ea6050",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa = RetrievalQA.from_chain_type(llm=llm, chain_type=\"stuff\", retriever=docsearch.as_retriever())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "728de8ed-13d4-4191-9bc8-717b10b28e85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'美猴王的师傅是须菩提祖师。'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query = \"西游记里面美猴王的师傅是谁？\"\n",
    "qa.run(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "989d8209-6b4c-443d-b810-05e136f67d97",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 帮助构建我们的聊天信息\n",
    "from langchain.schema import HumanMessage\n",
    "from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate\n",
    "\n",
    "# 解析输出并获取结构化数据\n",
    "from langchain.output_parsers import StructuredOutputParser, ResponseSchema\n",
    "\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "62ffa8ab-3d07-4e9c-ae42-e326f65ae373",
   "metadata": {},
   "outputs": [],
   "source": [
    "instructions = \"\"\"\n",
    "您将得到一个包含水果名称的句子，提取这些水果名称并为它们分配一个表情符号\n",
    "在 Python 字典中返回水果名称和表情符号\n",
    "\"\"\"\n",
    "\n",
    "fruit_names = \"\"\"\n",
    "苹果，梨，这是猕猴桃\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "690b0312-ca3c-49f6-b2e1-8d2502dd7188",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "要从句子中提取水果名称并为它们分配表情符号，我们可以创建一个 Python 字典来映射水果名称到对应的表情符号。以下是可能的解决方案：\n",
      "\n",
      "```python\n",
      "# 定义水果名称到表情符号的映射\n",
      "fruit_emojis = {\n",
      "    \"苹果\": \"🍎\",\n",
      "    \"梨\": \"🍐\",\n",
      "    \"猕猴桃\": \"🥝\"\n",
      "}\n",
      "\n",
      "# 输入的句子\n",
      "sentence = \"苹果，梨，这是猕猴桃\"\n",
      "\n",
      "# 提取水果名称\n",
      "fruits_in_sentence = [fruit for fruit in fruit_emojis.keys() if fruit in sentence]\n",
      "\n",
      "# 创建结果字典\n",
      "result = {fruit: fruit_emojis[fruit] for fruit in fruits_in_sentence}\n",
      "\n",
      "print(result)\n",
      "```\n",
      "\n",
      "输出将是：\n",
      "\n",
      "```python\n",
      "{'苹果': '🍎', '梨': '🍐', '猕猴桃': '🥝'}\n",
      "```\n",
      "\n",
      "这个代码片段从给定的句子中提取水果名称，并使用预定义的表情符号字典返回它们的对应关系。\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 制作将说明与水果名称结合起来的提示\n",
    "prompt = (instructions + fruit_names)\n",
    "\n",
    "# 调用LLM\n",
    "output = llm([HumanMessage(content=prompt)])\n",
    "\n",
    "print (output.content)\n",
    "print (type(output.content))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c7dd495b-356e-4bf8-b2cc-4f814510dbca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 我们想要的格式\n",
    "response_schemas = [\n",
    "    ResponseSchema(name=\"艺术家\", description=\"音乐艺术家的姓名\"),\n",
    "    ResponseSchema(name=\"歌曲\", description=\"艺术家演奏的歌曲名称\")\n",
    "]\n",
    "\n",
    "# 解析器将在我的模式中查找 LLM 输出并将其返回给我\n",
    "output_parser = StructuredOutputParser.from_response_schemas(response_schemas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "cf34340e-8529-4834-9fe3-559dd7222535",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output should be a markdown code snippet formatted in the following schema, including the leading and trailing \"```json\" and \"```\":\n",
      "\n",
      "```json\n",
      "{\n",
      "\t\"艺术家\": string  // 音乐艺术家的姓名\n",
      "\t\"歌曲\": string  // 艺术家演奏的歌曲名称\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "# LangChain相应模式后面的提示词让我们来看看\n",
    "format_instructions = output_parser.get_format_instructions()\n",
    "print(format_instructions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "b6d75cc5-7578-463d-a4a3-f2e34f1282bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提供完整的提示模板\n",
    "# 注意: 这是一个不同的提示模板，因为我们使用的是聊天模型\n",
    "\n",
    "prompt = ChatPromptTemplate(\n",
    "    messages=[\n",
    "        HumanMessagePromptTemplate.from_template(\"根据用户的指令，提取所有艺术家和歌曲名称 \\n \\\n",
    "                                                    {format_instructions}\\n{user_prompt}\")\n",
    "    ],\n",
    "    input_variables=[\"user_prompt\"],\n",
    "    partial_variables={\"format_instructions\": format_instructions}\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "20e42953-bccf-490a-aa16-7987aabf7bbb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "根据用户的指令，提取所有艺术家和歌曲名称 \n",
      "                                                     The output should be a markdown code snippet formatted in the following schema, including the leading and trailing \"```json\" and \"```\":\n",
      "\n",
      "```json\n",
      "{\n",
      "\t\"艺术家\": string  // 音乐艺术家的姓名\n",
      "\t\"歌曲\": string  // 艺术家演奏的歌曲名称\n",
      "}\n",
      "```\n",
      "在当代华语乐坛，周杰伦以其独特的风格创作了诸如《七里香》等经典作品。\n"
     ]
    }
   ],
   "source": [
    "fruit_query = prompt.format_prompt(user_prompt=\"在当代华语乐坛，周杰伦以其独特的风格创作了诸如《七里香》等经典作品。\")\n",
    "print (fruit_query.messages[0].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "547b6625-6591-4561-87a9-de8351cf2e3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'艺术家': '周杰伦', '歌曲': '七里香'}\n",
      "<class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "fruit_output = llm(fruit_query.to_messages())\n",
    "output = output_parser.parse(fruit_output.content)\n",
    "\n",
    "print (output)\n",
    "print (type(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3de01396-be52-402a-88d3-5c992851c101",
   "metadata": {},
   "source": [
    "## 评估\n",
    "LangChain评估官方文档\n",
    "\n",
    "评估是对应用程序输出进行质量检查的过程。正常的、确定性的代码有我们可以运行的测试，但由于自然语言的不可预测性和多边性，判断LLM的输出更加困难。\n",
    "LangChain提供了可帮助我们完成这一旅程的工具\n",
    "\n",
    "- 用例： 对摘要或问答管道运行质量检查，检查管道的输出质量\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "91289c20-c768-48c7-b178-1830d93cd4fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 嵌入、存储和检索\n",
    "from langchain.embeddings.openai import OpenAIEmbeddings\n",
    "from langchain.vectorstores import FAISS\n",
    "from langchain.chains import RetrievalQA\n",
    "\n",
    "# 模型和文档加载\n",
    "from langchain.document_loaders import TextLoader\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")\n",
    "\n",
    "# 评估链\n",
    "from langchain.evaluation.qa import QAEvalChain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "814fb4c9-dc10-4136-9c20-c5597bed4928",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您有 1 个文档\n",
      "该文档中有 74663 个字符\n"
     ]
    }
   ],
   "source": [
    "loader = TextLoader('./data/worked.txt')\n",
    "doc = loader.load()\n",
    "\n",
    "print(f\"您有 {len(doc)} 个文档\")\n",
    "print(f\"该文档中有 {len(doc[0].page_content)} 个字符\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "0767dd39-4603-4c57-939e-2075c116a87c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "现在您有 29 个文档，每个文档平均有 2,930 个字符（较小的部分）\n"
     ]
    }
   ],
   "source": [
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "\n",
    "text_splitter = RecursiveCharacterTextSplitter(chunk_size=3000, chunk_overlap=400)\n",
    "docs = text_splitter.split_documents(doc)\n",
    "\n",
    "# 获取字符总数，以便我们稍后查看平均值\n",
    "num_total_characters = sum([len(x.page_content) for x in docs])\n",
    "\n",
    "print(f\"现在您有 {len(docs)} 个文档，每个文档平均有 {num_total_characters / len(docs):,.0f} 个字符（较小的部分）\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "5e85864f-ac77-4c80-9959-45e819be6588",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 嵌入和文档存储\n",
    "embeddings = OpenAIEmbeddings()\n",
    "docsearch = FAISS.from_documents(docs, embeddings)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3e8e5378-d83d-41be-9762-959554f9240c",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = RetrievalQA.from_chain_type(llm=llm, chain_type=\"stuff\", retriever=docsearch.as_retriever(), input_key=\"question\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "ed9ab239-61ff-4424-b666-ac097d8fbaae",
   "metadata": {},
   "outputs": [],
   "source": [
    "question_answers = [\n",
    "    {'question' : \"Which company sold the microcomputer kit that his friend built himself?\", 'answer' : 'Heathkit'},\n",
    "    {'question' : \"What was the small city he talked about in the city that is the financial capital of USA?\", 'answer' : 'Yorkville, NY'}\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db74a979-241d-4fbf-98d4-abd27c1c315b",
   "metadata": {},
   "source": [
    "我将使用 chain.apply分别逐一运行我的两个问题。\n",
    "其中一个很酷的部分是，我将返回问题和答案字典列表，但字典中会有另一个键result ，它将是LLM的输出。\n",
    "\n",
    "注意：我特意将我的第二个问题弄得模棱两可，难以一次性回答，这样LLM就会答错\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "4716283d-2009-4ba6-ab7e-c00ab580e4ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_17836\\724901087.py:1: LangChainDeprecationWarning: The method `Chain.apply` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use batch instead.\n",
      "  predictions = chain.apply(question_answers)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'question': 'Which company sold the microcomputer kit that his friend built himself?',\n",
       "  'answer': 'Heathkit',\n",
       "  'result': 'Heathkit sold the microcomputer kit that his friend built himself.'},\n",
       " {'question': 'What was the small city he talked about in the city that is the financial capital of USA?',\n",
       "  'answer': 'Yorkville, NY',\n",
       "  'result': 'The small city he talked about is Yorkville, which was his new home in the financial capital of the USA, New York City.'}]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions = chain.apply(question_answers)\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de149931-0ce0-45d5-be30-9de33458b6b5",
   "metadata": {},
   "source": [
    "然后，我们让LLM将我的标注答案（Answer）与LLM的结果（Result）进行比较。\n",
    "或者简单地说，我们要求LLM自己评理。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "4caff0e6-e3cd-4c9e-bcdc-b91c199b9804",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:360: UserWarning: Unexpected type for token usage: <class 'NoneType'>\n",
      "  warnings.warn(f\"Unexpected type for token usage: {type(new_usage)}\")\n"
     ]
    }
   ],
   "source": [
    "# 初始化eval链接\n",
    "eval_chain = QAEvalChain.from_llm(llm)\n",
    "\n",
    "# 让它自己评分。下面的代码帮助 eval_chain 知道不同部分的位置\n",
    "graded_outputs = eval_chain.evaluate(question_answers,\n",
    "                                     predictions,\n",
    "                                     question_key=\"question\",\n",
    "                                     prediction_key=\"result\",\n",
    "                                     answer_key='answer')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "008ef82c-3efe-4396-be06-0588b30979f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'results': 'CORRECT'}, {'results': 'CORRECT'}]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graded_outputs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3cb9ebb-f867-4939-86ca-20b404b9f54a",
   "metadata": {},
   "source": [
    "## 查询表格数据\n",
    "除了非结构化数据，世界上最常见的数据类型是表格形式。我们能够使用LangChain查询这些数据并将其传递给LLM进行分析\n",
    "\n",
    "- 用例： 使用LLM查询有关用户的数据、进行数据分析、从数据库获取实时信息\n",
    "\n",
    "\n",
    "本实例中让我们使用自然语言查SQLite 数据库。 https://sqliteviewer.app/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "80d78717-b199-4e62-b938-3ff165347a00",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pydantic==2.9.2 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (2.9.2)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from pydantic==2.9.2) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from pydantic==2.9.2) (2.23.4)\n",
      "Requirement already satisfied: typing-extensions>=4.6.1 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from pydantic==2.9.2) (4.13.2)\n"
     ]
    }
   ],
   "source": [
    "!pip install -q langchain_experimental\n",
    "!pip install pydantic==2.9.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8aa59d06-b7fd-4063-8696-e2aab4251875",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.sql_database import SQLDatabase\n",
    "from langchain_experimental.sql import SQLDatabaseChain\n",
    "\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e45bcef1-bf5b-4aaf-8943-427ce3e3f81e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sqlite_db_path = './data/San_Francisco_Trees.db'\n",
    "# sqlite_db_path = '/content/San_Francisco_Trees.db'\n",
    "db = SQLDatabase.from_uri(f\"sqlite:///{sqlite_db_path}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "88b183fc-3633-48e2-9bb1-5826b2f6fde3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "578\n"
     ]
    }
   ],
   "source": [
    "from sqlalchemy import create_engine, text\n",
    "\n",
    "# ✅ 直接创建 SQLAlchemy 引擎\n",
    "sqlite_db_path = './data/San_Francisco_Trees.db'\n",
    "engine = create_engine(f\"sqlite:///{sqlite_db_path}\")\n",
    "\n",
    "# 执行查询\n",
    "with engine.connect() as conn:\n",
    "    result = conn.execute(text('SELECT COUNT(DISTINCT \"qSpecies\") FROM \"SFTrees\"'))\n",
    "    print(result.scalar())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a4f241e5-53ba-47a5-b26f-c650c2e59c91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "578\n"
     ]
    }
   ],
   "source": [
    "from sqlalchemy import text\n",
    "\n",
    "# 假设 db 是已创建的 SQLDatabase 实例\n",
    "engine = db._engine  # ✅ 访问内部引擎（风险：非公开API）\n",
    "\n",
    "with engine.connect() as conn:\n",
    "    result = conn.execute(text('SELECT COUNT(DISTINCT \"qSpecies\") FROM \"SFTrees\"'))\n",
    "    print(result.scalar())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "66ad1a0f-5c7d-4b5e-8544-5cc0b2efd8b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "旧金山共有 578 种不同的树种。\n"
     ]
    }
   ],
   "source": [
    "from sqlalchemy import create_engine, text\n",
    "\n",
    "# 配置数据库路径\n",
    "sqlite_db_path = './data/San_Francisco_Trees.db'\n",
    "\n",
    "# 直接创建 SQLAlchemy 引擎\n",
    "engine = create_engine(f\"sqlite:///{sqlite_db_path}\")\n",
    "\n",
    "# 执行查询\n",
    "with engine.connect() as conn:\n",
    "    # 查询旧金山树种数\n",
    "    query = text('SELECT COUNT(DISTINCT \"qSpecies\") FROM \"SFTrees\"')\n",
    "    result = conn.execute(query)\n",
    "    species_count = result.scalar()\n",
    "    print(f\"旧金山共有 {species_count} 种不同的树种。\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a98da9c-b213-42b7-9db2-64d6bbe0b565",
   "metadata": {},
   "source": [
    "实际上这里有几个步骤。\n",
    "\n",
    "## 步骤\n",
    "    1.找到要使用的表 \n",
    "    2.找到要使用的列 \n",
    "    3.构建正确的sql查询 \n",
    "    4.执行该查询 \n",
    "    5.获取结果 \n",
    "    6.返回自然语言响应 \n",
    "\n",
    "让我们通过pandas进行确认\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "405fa09a-bb1a-4884-9433-acc0477053d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sqlite3\n",
    "import pandas as pd\n",
    "\n",
    "# 连接到 SQLite 数据库\n",
    "connection = sqlite3.connect(sqlite_db_path)\n",
    "\n",
    "# 定义你的 SQL 查询\n",
    "query = \"SELECT count(distinct qSpecies) FROM SFTrees\"\n",
    "\n",
    "# 将 SQL 查询读入 Pandas DataFrame\n",
    "df = pd.read_sql_query(query, connection)\n",
    "\n",
    "# 关闭连接\n",
    "connection.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3f7a691e-e6dc-4dba-aef0-d684f62e749f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "578\n"
     ]
    }
   ],
   "source": [
    "# 在第一列第一个单元格中显示结果\n",
    "print(df.iloc[0,0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dde77c77-54a0-4f19-b9c7-6366cd39fc7e",
   "metadata": {},
   "source": [
    "## 代码理解\n",
    "LLM最令人兴奋的能力之一是代码理解。由于人工智能的帮助，世界各地的人们都在提高速度和质量。其中很大一部分是拥有一个可以理解代码并帮助您完成特定任务的LLM。\n",
    "\n",
    " - 用例： Co-Pilot式功能可以帮助回答特定库中的问题，帮助您生成新代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "a884fd96-3d7d-443a-bf56-97327bfe7830",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 帮助读取本地文件\n",
    "import os\n",
    "\n",
    "# 向量化\n",
    "from langchain.vectorstores import FAISS\n",
    "from langchain.embeddings.openai import OpenAIEmbeddings\n",
    "\n",
    "# 切分文档\n",
    "from langchain.text_splitter import CharacterTextSplitter\n",
    "from langchain.document_loaders import TextLoader\n",
    "\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "fd0fdfa8-6388-4c44-91e3-b60006f22740",
   "metadata": {},
   "outputs": [],
   "source": [
    "embeddings = OpenAIEmbeddings()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2d41178d-9943-455b-95de-c8d6321e7b30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pydrive2\n",
      "  Downloading PyDrive2-1.21.3-py3-none-any.whl.metadata (7.0 kB)\n",
      "Collecting google-api-python-client\n",
      "  Downloading google_api_python_client-2.167.0-py2.py3-none-any.whl.metadata (6.7 kB)\n",
      "Collecting oauth2client>=4.0.0 (from pydrive2)\n",
      "  Downloading oauth2client-4.1.3-py2.py3-none-any.whl.metadata (1.2 kB)\n",
      "Requirement already satisfied: PyYAML>=3.0 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from pydrive2) (6.0.2)\n",
      "Collecting cryptography<44 (from pydrive2)\n",
      "  Downloading cryptography-43.0.3-cp37-abi3-win_amd64.whl.metadata (5.4 kB)\n",
      "Collecting pyOpenSSL<=24.2.1,>=19.1.0 (from pydrive2)\n",
      "  Downloading pyOpenSSL-24.2.1-py3-none-any.whl.metadata (13 kB)\n",
      "Collecting httplib2<1.0.0,>=0.19.0 (from google-api-python-client)\n",
      "  Downloading httplib2-0.22.0-py3-none-any.whl.metadata (2.6 kB)\n",
      "Requirement already satisfied: google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-api-python-client) (2.38.0)\n",
      "Collecting google-auth-httplib2<1.0.0,>=0.2.0 (from google-api-python-client)\n",
      "  Downloading google_auth_httplib2-0.2.0-py2.py3-none-any.whl.metadata (2.2 kB)\n",
      "Collecting google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5 (from google-api-python-client)\n",
      "  Downloading google_api_core-2.24.2-py3-none-any.whl.metadata (3.0 kB)\n",
      "Collecting uritemplate<5,>=3.0.1 (from google-api-python-client)\n",
      "  Downloading uritemplate-4.1.1-py2.py3-none-any.whl.metadata (2.9 kB)\n",
      "Requirement already satisfied: cffi>=1.12 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from cryptography<44->pydrive2) (1.17.1)\n",
      "Requirement already satisfied: googleapis-common-protos<2.0.0,>=1.56.2 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (1.70.0)\n",
      "Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<7.0.0,>=3.19.5 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (5.29.4)\n",
      "Collecting proto-plus<2.0.0,>=1.22.3 (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client)\n",
      "  Downloading proto_plus-1.26.1-py3-none-any.whl.metadata (2.2 kB)\n",
      "Requirement already satisfied: requests<3.0.0,>=2.18.0 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (2.32.3)\n",
      "Requirement already satisfied: cachetools<6.0,>=2.0.0 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (5.5.2)\n",
      "Requirement already satisfied: pyasn1-modules>=0.2.1 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (0.4.1)\n",
      "Requirement already satisfied: rsa<5,>=3.1.4 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (4.9)\n",
      "Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from httplib2<1.0.0,>=0.19.0->google-api-python-client) (3.0.9)\n",
      "Requirement already satisfied: pyasn1>=0.1.7 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from oauth2client>=4.0.0->pydrive2) (0.6.1)\n",
      "Requirement already satisfied: six>=1.6.1 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from oauth2client>=4.0.0->pydrive2) (1.16.0)\n",
      "Requirement already satisfied: pycparser in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from cffi>=1.12->cryptography<44->pydrive2) (2.21)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (3.3.2)\n",
      "Requirement already satisfied: idna<4,>=2.5 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (3.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (1.25.11)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in d:\\cachedata\\anaconda\\envs\\hanlp-python38\\lib\\site-packages (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (2024.8.30)\n",
      "Downloading PyDrive2-1.21.3-py3-none-any.whl (47 kB)\n",
      "Downloading google_api_python_client-2.167.0-py2.py3-none-any.whl (13.2 MB)\n",
      "   ---------------------------------------- 0.0/13.2 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/13.2 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/13.2 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "    --------------------------------------- 0.3/13.2 MB ? eta -:--:--\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   - -------------------------------------- 0.5/13.2 MB 117.3 kB/s eta 0:01:49\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   -- ------------------------------------- 0.8/13.2 MB 80.1 kB/s eta 0:02:36\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.0/13.2 MB 74.0 kB/s eta 0:02:45\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   --- ------------------------------------ 1.3/13.2 MB 83.6 kB/s eta 0:02:23\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ---- ----------------------------------- 1.6/13.2 MB 86.1 kB/s eta 0:02:16\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ----- ---------------------------------- 1.8/13.2 MB 79.4 kB/s eta 0:02:24\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------ --------------------------------- 2.1/13.2 MB 81.4 kB/s eta 0:02:17\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.4/13.2 MB 72.8 kB/s eta 0:02:30\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   ------- -------------------------------- 2.6/13.2 MB 69.4 kB/s eta 0:02:34\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   -------- ------------------------------- 2.9/13.2 MB 61.7 kB/s eta 0:02:48\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   --------- ------------------------------ 3.1/13.2 MB 53.6 kB/s eta 0:03:09\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ---------- ----------------------------- 3.4/13.2 MB 53.9 kB/s eta 0:03:03\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.7/13.2 MB 53.5 kB/s eta 0:02:59\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ----------- ---------------------------- 3.9/13.2 MB 56.0 kB/s eta 0:02:47\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------ --------------------------- 4.2/13.2 MB 56.9 kB/s eta 0:02:39\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   ------------- -------------------------- 4.5/13.2 MB 59.2 kB/s eta 0:02:29\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   -------------- ------------------------- 4.7/13.2 MB 64.1 kB/s eta 0:02:13\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.0/13.2 MB 70.3 kB/s eta 0:01:58\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   --------------- ------------------------ 5.2/13.2 MB 71.3 kB/s eta 0:01:53\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ---------------- ----------------------- 5.5/13.2 MB 72.9 kB/s eta 0:01:47\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ----------------- ---------------------- 5.8/13.2 MB 74.8 kB/s eta 0:01:40\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------ --------------------- 6.0/13.2 MB 80.8 kB/s eta 0:01:30\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.3/13.2 MB 82.6 kB/s eta 0:01:25\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   ------------------- -------------------- 6.6/13.2 MB 98.2 kB/s eta 0:01:09\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   -------------------- ------------------- 6.8/13.2 MB 101.5 kB/s eta 0:01:04\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   --------------------- ------------------ 7.1/13.2 MB 103.4 kB/s eta 0:01:00\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.3/13.2 MB 106.5 kB/s eta 0:00:56\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ---------------------- ----------------- 7.6/13.2 MB 113.2 kB/s eta 0:00:50\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ----------------------- ---------------- 7.9/13.2 MB 116.8 kB/s eta 0:00:47\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------ --------------- 8.1/13.2 MB 118.1 kB/s eta 0:00:44\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   ------------------------- -------------- 8.4/13.2 MB 118.7 kB/s eta 0:00:41\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.7/13.2 MB 120.6 kB/s eta 0:00:39\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   -------------------------- ------------- 8.9/13.2 MB 123.3 kB/s eta 0:00:36\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   --------------------------- ------------ 9.2/13.2 MB 130.0 kB/s eta 0:00:32\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ---------------------------- ----------- 9.4/13.2 MB 131.1 kB/s eta 0:00:29\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ----------------------------- ---------- 9.7/13.2 MB 133.8 kB/s eta 0:00:27\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.0/13.2 MB 132.7 kB/s eta 0:00:25\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------ --------- 10.2/13.2 MB 135.8 kB/s eta 0:00:23\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   ------------------------------- -------- 10.5/13.2 MB 137.7 kB/s eta 0:00:20\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   -------------------------------- ------- 10.7/13.2 MB 138.3 kB/s eta 0:00:18\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   --------------------------------- ------ 11.0/13.2 MB 135.8 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.3/13.2 MB 118.9 kB/s eta 0:00:17\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ---------------------------------- ----- 11.5/13.2 MB 117.5 kB/s eta 0:00:15\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ----------------------------------- ---- 11.8/13.2 MB 120.9 kB/s eta 0:00:12\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------ --- 12.1/13.2 MB 119.9 kB/s eta 0:00:10\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   ------------------------------------- -- 12.3/13.2 MB 109.7 kB/s eta 0:00:09\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.6/13.2 MB 105.1 kB/s eta 0:00:07\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   -------------------------------------- - 12.8/13.2 MB 106.4 kB/s eta 0:00:04\n",
      "   ---------------------------------------  13.1/13.2 MB 108.3 kB/s eta 0:00:02\n",
      "   ---------------------------------------  13.1/13.2 MB 108.3 kB/s eta 0:00:02\n",
      "   ---------------------------------------  13.1/13.2 MB 108.3 kB/s eta 0:00:02\n",
      "   ---------------------------------------  13.1/13.2 MB 108.3 kB/s eta 0:00:02\n",
      "   ---------------------------------------  13.1/13.2 MB 108.3 kB/s eta 0:00:02\n",
      "   ---------------------------------------- 13.2/13.2 MB 106.9 kB/s eta 0:00:00\n",
      "Downloading cryptography-43.0.3-cp37-abi3-win_amd64.whl (3.1 MB)\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   ---------------------------------------- 0.0/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   --- ------------------------------------ 0.3/3.1 MB ? eta -:--:--\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ------ --------------------------------- 0.5/3.1 MB 164.5 kB/s eta 0:00:16\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ---------- ----------------------------- 0.8/3.1 MB 180.4 kB/s eta 0:00:13\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ------------- -------------------------- 1.0/3.1 MB 177.2 kB/s eta 0:00:12\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   ----------------- ---------------------- 1.3/3.1 MB 180.4 kB/s eta 0:00:10\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   -------------------- ------------------- 1.6/3.1 MB 171.9 kB/s eta 0:00:09\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   ----------------------- ---------------- 1.8/3.1 MB 175.7 kB/s eta 0:00:08\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   --------------------------- ------------ 2.1/3.1 MB 180.1 kB/s eta 0:00:06\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ------------------------------ --------- 2.4/3.1 MB 184.9 kB/s eta 0:00:04\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ---------------------------------- ----- 2.6/3.1 MB 177.4 kB/s eta 0:00:03\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ------------------------------------- -- 2.9/3.1 MB 169.8 kB/s eta 0:00:02\n",
      "   ---------------------------------------- 3.1/3.1 MB 163.4 kB/s eta 0:00:00\n",
      "Downloading google_api_core-2.24.2-py3-none-any.whl (160 kB)\n",
      "Downloading google_auth_httplib2-0.2.0-py2.py3-none-any.whl (9.3 kB)\n",
      "Downloading httplib2-0.22.0-py3-none-any.whl (96 kB)\n",
      "Downloading oauth2client-4.1.3-py2.py3-none-any.whl (98 kB)\n",
      "Downloading pyOpenSSL-24.2.1-py3-none-any.whl (58 kB)\n",
      "Downloading uritemplate-4.1.1-py2.py3-none-any.whl (10 kB)\n",
      "Downloading proto_plus-1.26.1-py3-none-any.whl (50 kB)\n",
      "Installing collected packages: uritemplate, proto-plus, httplib2, oauth2client, cryptography, pyOpenSSL, google-auth-httplib2, google-api-core, google-api-python-client, pydrive2\n",
      "  Attempting uninstall: cryptography\n",
      "    Found existing installation: cryptography 44.0.2\n",
      "    Uninstalling cryptography-44.0.2:\n",
      "      Successfully uninstalled cryptography-44.0.2\n",
      "Successfully installed cryptography-43.0.3 google-api-core-2.24.2 google-api-python-client-2.167.0 google-auth-httplib2-0.2.0 httplib2-0.22.0 oauth2client-4.1.3 proto-plus-1.26.1 pyOpenSSL-24.2.1 pydrive2-1.21.3 uritemplate-4.1.1\n"
     ]
    }
   ],
   "source": [
    "!pip install pydrive2 google-api-python-client"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "48eb6a65-b69a-4a97-b182-9eba0020c3a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR: Could not find a version that satisfies the requirement google-colab (from versions: none)\n",
      "ERROR: No matching distribution found for google-colab\n"
     ]
    }
   ],
   "source": [
    "!pip install google-colab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "72bd6b43-5c11-40b1-ade4-9662e264415e",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'google.colab'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[33], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydrive2\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mauth\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m GoogleAuth\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydrive2\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdrive\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m GoogleDrive\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgoogle\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcolab\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m auth  \u001b[38;5;66;03m# 本地环境需替换为此方法\u001b[39;00m\n\u001b[0;32m      5\u001b[0m \u001b[38;5;66;03m# 本地授权（会打开浏览器进行 OAuth 登录）\u001b[39;00m\n\u001b[0;32m      6\u001b[0m gauth \u001b[38;5;241m=\u001b[39m GoogleAuth()\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'google.colab'"
     ]
    }
   ],
   "source": [
    "from pydrive2.auth import GoogleAuth\n",
    "from pydrive2.drive import GoogleDrive\n",
    "from google.colab import auth  # 本地环境需替换为此方法\n",
    "\n",
    "# 本地授权（会打开浏览器进行 OAuth 登录）\n",
    "gauth = GoogleAuth()\n",
    "gauth.LocalWebserverAuth()  # 授权后返回验证码\n",
    "\n",
    "# 创建 GoogleDrive 客户端\n",
    "drive = GoogleDrive(gauth)\n",
    "\n",
    "# 列出根目录下的文件（验证授权）\n",
    "file_list = drive.ListFile({'q': \"'root' in parents and trashed=false\"}).GetList()\n",
    "for file in file_list:\n",
    "    print(f\"文件名: {file['title']}, ID: {file['id']}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "74af51ef-15e8-4e1b-836a-10eaa706d5a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'google.colab'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[36], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgoogle\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcolab\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m drive\n\u001b[0;32m      2\u001b[0m drive\u001b[38;5;241m.\u001b[39mmount(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/content/drive\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'google.colab'"
     ]
    }
   ],
   "source": [
    "from google.colab import drive\n",
    "drive.mount('/content/drive')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a963c83-1a18-42fd-8bdf-3e0a5068ad6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "root_dir = '/content/drive/MyDrive/thefuzz'\n",
    "docs = []\n",
    "\n",
    "# 浏览每个文件夹\n",
    "for dirpath, dirnames, filenames in os.walk(root_dir):\n",
    "\n",
    "    # 浏览每个文件\n",
    "    for file in filenames:\n",
    "        try:\n",
    "            # 将文件加载为文档并拆分\n",
    "            loader = TextLoader(os.path.join(dirpath, file), encoding='utf-8')\n",
    "            docs.extend(loader.load_and_split())\n",
    "        except Exception as e:\n",
    "            pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f98edcb7-9525-4a13-864b-2d3c95511f6a",
   "metadata": {},
   "source": [
    "## 与API交互\n",
    "如果您需要的数据或操作位于API后面，则需要LLM与API交互\n",
    "\n",
    " - 用例：了解用户的请求并执行操作，能够自动化更多实际工作流程\n",
    "\n",
    "此主题与Agent和插件密切相关，我们在本部分中只是介绍一个简单的用例。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "baffebb4-6654-4c2b-9e42-0c3b30b7d724",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chains import APIChain\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "api_key = os.environ.get('OPENAI_API_KEY')\n",
    "base_url = os.environ.get('OPENAI_BASE_URL')\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0a9f355e-6cf7-4d1b-920a-7c1313e38897",
   "metadata": {},
   "outputs": [],
   "source": [
    "api_docs = \"\"\"\n",
    "\n",
    "BASE URL: https://restcountries.com/\n",
    "\n",
    "API Documentation:\n",
    "\n",
    "The API endpoint /v3.1/name/{name} Used to find informatin about a country. All URL parameters are listed below:\n",
    "    - name: Name of country - Ex: italy, france\n",
    "\n",
    "The API endpoint /v3.1/currency/{currency} Uesd to find information about a region. All URL parameters are listed below:\n",
    "    - currency: 3 letter currency. Example: USD, COP\n",
    "\n",
    "This is the doc\n",
    "\"\"\"\n",
    "\n",
    "chain_new = APIChain.from_llm_and_api_docs(llm, api_docs, verbose=True, limit_to_domains=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "b091fb76-36b3-4427-8b60-57a1098eeeb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "{'message': 'Not enough available apiNum,your key is sk-************3tNLwf, Please go to recharge', 'type': 'invalid_request_error', 'param': None, 'code': None}",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[45], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mchain_new\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mCan you tell me some information about France?\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:597\u001b[0m, in \u001b[0;36mChain.run\u001b[1;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[0;32m    595\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m    596\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 597\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[0;32m    598\u001b[0m         _output_key\n\u001b[0;32m    599\u001b[0m     ]\n\u001b[0;32m    601\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[0;32m    602\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[0;32m    603\u001b[0m         _output_key\n\u001b[0;32m    604\u001b[0m     ]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:380\u001b[0m, in \u001b[0;36mChain.__call__\u001b[1;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[0;32m    348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Execute the chain.\u001b[39;00m\n\u001b[0;32m    349\u001b[0m \n\u001b[0;32m    350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    371\u001b[0m \u001b[38;5;124;03m        `Chain.output_keys`.\u001b[39;00m\n\u001b[0;32m    372\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    373\u001b[0m config \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m    374\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks,\n\u001b[0;32m    375\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m: tags,\n\u001b[0;32m    376\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[0;32m    377\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m: run_name,\n\u001b[0;32m    378\u001b[0m }\n\u001b[1;32m--> 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    381\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRunnableConfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43mk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    383\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[43m    \u001b[49m\u001b[43minclude_run_info\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minclude_run_info\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    385\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    162\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[1;32m--> 163\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[0;32m    166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    151\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[0;32m    152\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m--> 153\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    154\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[0;32m    155\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[0;32m    156\u001b[0m     )\n\u001b[0;32m    158\u001b[0m     final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[0;32m    159\u001b[0m         inputs, outputs, return_only_outputs\n\u001b[0;32m    160\u001b[0m     )\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\api\\base.py:279\u001b[0m, in \u001b[0;36mAPIChain._call\u001b[1;34m(self, inputs, run_manager)\u001b[0m\n\u001b[0;32m    277\u001b[0m _run_manager \u001b[38;5;241m=\u001b[39m run_manager \u001b[38;5;129;01mor\u001b[39;00m CallbackManagerForChainRun\u001b[38;5;241m.\u001b[39mget_noop_manager()\n\u001b[0;32m    278\u001b[0m question \u001b[38;5;241m=\u001b[39m inputs[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mquestion_key]\n\u001b[1;32m--> 279\u001b[0m api_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_request_chain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpredict\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    280\u001b[0m \u001b[43m    \u001b[49m\u001b[43mquestion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquestion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    281\u001b[0m \u001b[43m    \u001b[49m\u001b[43mapi_docs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_docs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    282\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_run_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    283\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    284\u001b[0m _run_manager\u001b[38;5;241m.\u001b[39mon_text(api_url, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgreen\u001b[39m\u001b[38;5;124m\"\u001b[39m, end\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mverbose)\n\u001b[0;32m    285\u001b[0m api_url \u001b[38;5;241m=\u001b[39m api_url\u001b[38;5;241m.\u001b[39mstrip()\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:315\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[1;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[0;32m    300\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpredict\u001b[39m(\u001b[38;5;28mself\u001b[39m, callbacks: Callbacks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[0;32m    301\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[0;32m    302\u001b[0m \n\u001b[0;32m    303\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    313\u001b[0m \u001b[38;5;124;03m            completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[0;32m    314\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[1;32m--> 315\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:380\u001b[0m, in \u001b[0;36mChain.__call__\u001b[1;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[0;32m    348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Execute the chain.\u001b[39;00m\n\u001b[0;32m    349\u001b[0m \n\u001b[0;32m    350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    371\u001b[0m \u001b[38;5;124;03m        `Chain.output_keys`.\u001b[39;00m\n\u001b[0;32m    372\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    373\u001b[0m config \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m    374\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks,\n\u001b[0;32m    375\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m: tags,\n\u001b[0;32m    376\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[0;32m    377\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m: run_name,\n\u001b[0;32m    378\u001b[0m }\n\u001b[1;32m--> 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    381\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRunnableConfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43mk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    383\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[43m    \u001b[49m\u001b[43minclude_run_info\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minclude_run_info\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    385\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    162\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[1;32m--> 163\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[0;32m    166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    151\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[0;32m    152\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m--> 153\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    154\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[0;32m    155\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[0;32m    156\u001b[0m     )\n\u001b[0;32m    158\u001b[0m     final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[0;32m    159\u001b[0m         inputs, outputs, return_only_outputs\n\u001b[0;32m    160\u001b[0m     )\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:125\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[1;34m(self, inputs, run_manager)\u001b[0m\n\u001b[0;32m    120\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[0;32m    121\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m    122\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[0;32m    123\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m    124\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[1;32m--> 125\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    126\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:137\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[1;34m(self, input_list, run_manager)\u001b[0m\n\u001b[0;32m    135\u001b[0m callbacks \u001b[38;5;241m=\u001b[39m run_manager\u001b[38;5;241m.\u001b[39mget_child() \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m    136\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm, BaseLanguageModel):\n\u001b[1;32m--> 137\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    138\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    139\u001b[0m \u001b[43m        \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    140\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    141\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    142\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    143\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    144\u001b[0m     results \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm\u001b[38;5;241m.\u001b[39mbind(stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm_kwargs)\u001b[38;5;241m.\u001b[39mbatch(\n\u001b[0;32m    145\u001b[0m         cast(List, prompts), {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks}\n\u001b[0;32m    146\u001b[0m     )\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:777\u001b[0m, in \u001b[0;36mBaseChatModel.generate_prompt\u001b[1;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[0;32m    769\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[0;32m    770\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m    771\u001b[0m     prompts: List[PromptValue],\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    774\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[0;32m    775\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[0;32m    776\u001b[0m     prompt_messages \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_messages() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[1;32m--> 777\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_messages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:634\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[1;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[0;32m    632\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n\u001b[0;32m    633\u001b[0m             run_managers[i]\u001b[38;5;241m.\u001b[39mon_llm_error(e, response\u001b[38;5;241m=\u001b[39mLLMResult(generations\u001b[38;5;241m=\u001b[39m[]))\n\u001b[1;32m--> 634\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    635\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m    636\u001b[0m     LLMResult(generations\u001b[38;5;241m=\u001b[39m[res\u001b[38;5;241m.\u001b[39mgenerations], llm_output\u001b[38;5;241m=\u001b[39mres\u001b[38;5;241m.\u001b[39mllm_output)  \u001b[38;5;66;03m# type: ignore[list-item]\u001b[39;00m\n\u001b[0;32m    637\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results\n\u001b[0;32m    638\u001b[0m ]\n\u001b[0;32m    639\u001b[0m llm_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_combine_llm_outputs([res\u001b[38;5;241m.\u001b[39mllm_output \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results])\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:624\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[1;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[0;32m    621\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(messages):\n\u001b[0;32m    622\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    623\u001b[0m         results\u001b[38;5;241m.\u001b[39mappend(\n\u001b[1;32m--> 624\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_with_cache\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    625\u001b[0m \u001b[43m                \u001b[49m\u001b[43mm\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    626\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    627\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    628\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    629\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    630\u001b[0m         )\n\u001b[0;32m    631\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    632\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:846\u001b[0m, in \u001b[0;36mBaseChatModel._generate_with_cache\u001b[1;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m    844\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    845\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m--> 846\u001b[0m         result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    847\u001b[0m \u001b[43m            \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m    848\u001b[0m \u001b[43m        \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    849\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    850\u001b[0m         result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(messages, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:687\u001b[0m, in \u001b[0;36mBaseChatOpenAI._generate\u001b[1;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m    685\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    686\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclient\u001b[38;5;241m.\u001b[39mcreate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mpayload)\n\u001b[1;32m--> 687\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_chat_result\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgeneration_info\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:720\u001b[0m, in \u001b[0;36mBaseChatOpenAI._create_chat_result\u001b[1;34m(self, response, generation_info)\u001b[0m\n\u001b[0;32m    715\u001b[0m \u001b[38;5;66;03m# Sometimes the AI Model calling will get error, we should raise it.\u001b[39;00m\n\u001b[0;32m    716\u001b[0m \u001b[38;5;66;03m# Otherwise, the next code 'choices.extend(response[\"choices\"])'\u001b[39;00m\n\u001b[0;32m    717\u001b[0m \u001b[38;5;66;03m# will throw a \"TypeError: 'NoneType' object is not iterable\" error\u001b[39;00m\n\u001b[0;32m    718\u001b[0m \u001b[38;5;66;03m# to mask the true error. Because 'response[\"choices\"]' is None.\u001b[39;00m\n\u001b[0;32m    719\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merror\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m--> 720\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merror\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m    722\u001b[0m token_usage \u001b[38;5;241m=\u001b[39m response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124musage\u001b[39m\u001b[38;5;124m\"\u001b[39m, {})\n\u001b[0;32m    723\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m response_dict[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mchoices\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n",
      "\u001b[1;31mValueError\u001b[0m: {'message': 'Not enough available apiNum,your key is sk-************3tNLwf, Please go to recharge', 'type': 'invalid_request_error', 'param': None, 'code': None}"
     ]
    }
   ],
   "source": [
    "chain_new.run('Can you tell me some information about France?')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5207e0e6-0aec-497c-a688-4427609d8633",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "{'message': 'Not enough available apiNum,your key is sk-************3tNLwf, Please go to recharge', 'type': 'invalid_request_error', 'param': None, 'code': None}",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[40], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mchain_new\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mCan you tell me about the currency of CNY?\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:597\u001b[0m, in \u001b[0;36mChain.run\u001b[1;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[0;32m    595\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m    596\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 597\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[0;32m    598\u001b[0m         _output_key\n\u001b[0;32m    599\u001b[0m     ]\n\u001b[0;32m    601\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[0;32m    602\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[0;32m    603\u001b[0m         _output_key\n\u001b[0;32m    604\u001b[0m     ]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:380\u001b[0m, in \u001b[0;36mChain.__call__\u001b[1;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[0;32m    348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Execute the chain.\u001b[39;00m\n\u001b[0;32m    349\u001b[0m \n\u001b[0;32m    350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    371\u001b[0m \u001b[38;5;124;03m        `Chain.output_keys`.\u001b[39;00m\n\u001b[0;32m    372\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    373\u001b[0m config \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m    374\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks,\n\u001b[0;32m    375\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m: tags,\n\u001b[0;32m    376\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[0;32m    377\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m: run_name,\n\u001b[0;32m    378\u001b[0m }\n\u001b[1;32m--> 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    381\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRunnableConfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43mk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    383\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[43m    \u001b[49m\u001b[43minclude_run_info\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minclude_run_info\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    385\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    162\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[1;32m--> 163\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[0;32m    166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    151\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[0;32m    152\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m--> 153\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    154\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[0;32m    155\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[0;32m    156\u001b[0m     )\n\u001b[0;32m    158\u001b[0m     final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[0;32m    159\u001b[0m         inputs, outputs, return_only_outputs\n\u001b[0;32m    160\u001b[0m     )\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\api\\base.py:279\u001b[0m, in \u001b[0;36mAPIChain._call\u001b[1;34m(self, inputs, run_manager)\u001b[0m\n\u001b[0;32m    277\u001b[0m _run_manager \u001b[38;5;241m=\u001b[39m run_manager \u001b[38;5;129;01mor\u001b[39;00m CallbackManagerForChainRun\u001b[38;5;241m.\u001b[39mget_noop_manager()\n\u001b[0;32m    278\u001b[0m question \u001b[38;5;241m=\u001b[39m inputs[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mquestion_key]\n\u001b[1;32m--> 279\u001b[0m api_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_request_chain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpredict\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    280\u001b[0m \u001b[43m    \u001b[49m\u001b[43mquestion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquestion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    281\u001b[0m \u001b[43m    \u001b[49m\u001b[43mapi_docs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_docs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    282\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_run_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    283\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    284\u001b[0m _run_manager\u001b[38;5;241m.\u001b[39mon_text(api_url, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgreen\u001b[39m\u001b[38;5;124m\"\u001b[39m, end\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mverbose)\n\u001b[0;32m    285\u001b[0m api_url \u001b[38;5;241m=\u001b[39m api_url\u001b[38;5;241m.\u001b[39mstrip()\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:315\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[1;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[0;32m    300\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpredict\u001b[39m(\u001b[38;5;28mself\u001b[39m, callbacks: Callbacks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[0;32m    301\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[0;32m    302\u001b[0m \n\u001b[0;32m    303\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    313\u001b[0m \u001b[38;5;124;03m            completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[0;32m    314\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[1;32m--> 315\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:380\u001b[0m, in \u001b[0;36mChain.__call__\u001b[1;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[0;32m    348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Execute the chain.\u001b[39;00m\n\u001b[0;32m    349\u001b[0m \n\u001b[0;32m    350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    371\u001b[0m \u001b[38;5;124;03m        `Chain.output_keys`.\u001b[39;00m\n\u001b[0;32m    372\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    373\u001b[0m config \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m    374\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks,\n\u001b[0;32m    375\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m: tags,\n\u001b[0;32m    376\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[0;32m    377\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m: run_name,\n\u001b[0;32m    378\u001b[0m }\n\u001b[1;32m--> 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    381\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRunnableConfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43mk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    383\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[43m    \u001b[49m\u001b[43minclude_run_info\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minclude_run_info\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    385\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    162\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[1;32m--> 163\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[0;32m    166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    151\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[0;32m    152\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m--> 153\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    154\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[0;32m    155\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[0;32m    156\u001b[0m     )\n\u001b[0;32m    158\u001b[0m     final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[0;32m    159\u001b[0m         inputs, outputs, return_only_outputs\n\u001b[0;32m    160\u001b[0m     )\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:125\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[1;34m(self, inputs, run_manager)\u001b[0m\n\u001b[0;32m    120\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[0;32m    121\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m    122\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[0;32m    123\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m    124\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[1;32m--> 125\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    126\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\llm.py:137\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[1;34m(self, input_list, run_manager)\u001b[0m\n\u001b[0;32m    135\u001b[0m callbacks \u001b[38;5;241m=\u001b[39m run_manager\u001b[38;5;241m.\u001b[39mget_child() \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m    136\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm, BaseLanguageModel):\n\u001b[1;32m--> 137\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    138\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    139\u001b[0m \u001b[43m        \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    140\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    141\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    142\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    143\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    144\u001b[0m     results \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm\u001b[38;5;241m.\u001b[39mbind(stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mllm_kwargs)\u001b[38;5;241m.\u001b[39mbatch(\n\u001b[0;32m    145\u001b[0m         cast(List, prompts), {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks}\n\u001b[0;32m    146\u001b[0m     )\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:777\u001b[0m, in \u001b[0;36mBaseChatModel.generate_prompt\u001b[1;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[0;32m    769\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[0;32m    770\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m    771\u001b[0m     prompts: List[PromptValue],\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    774\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[0;32m    775\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[0;32m    776\u001b[0m     prompt_messages \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_messages() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[1;32m--> 777\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_messages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:634\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[1;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[0;32m    632\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n\u001b[0;32m    633\u001b[0m             run_managers[i]\u001b[38;5;241m.\u001b[39mon_llm_error(e, response\u001b[38;5;241m=\u001b[39mLLMResult(generations\u001b[38;5;241m=\u001b[39m[]))\n\u001b[1;32m--> 634\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    635\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m    636\u001b[0m     LLMResult(generations\u001b[38;5;241m=\u001b[39m[res\u001b[38;5;241m.\u001b[39mgenerations], llm_output\u001b[38;5;241m=\u001b[39mres\u001b[38;5;241m.\u001b[39mllm_output)  \u001b[38;5;66;03m# type: ignore[list-item]\u001b[39;00m\n\u001b[0;32m    637\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results\n\u001b[0;32m    638\u001b[0m ]\n\u001b[0;32m    639\u001b[0m llm_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_combine_llm_outputs([res\u001b[38;5;241m.\u001b[39mllm_output \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results])\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:624\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[1;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[0;32m    621\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(messages):\n\u001b[0;32m    622\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    623\u001b[0m         results\u001b[38;5;241m.\u001b[39mappend(\n\u001b[1;32m--> 624\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_with_cache\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    625\u001b[0m \u001b[43m                \u001b[49m\u001b[43mm\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    626\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    627\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    628\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    629\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    630\u001b[0m         )\n\u001b[0;32m    631\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    632\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\language_models\\chat_models.py:846\u001b[0m, in \u001b[0;36mBaseChatModel._generate_with_cache\u001b[1;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m    844\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    845\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m--> 846\u001b[0m         result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    847\u001b[0m \u001b[43m            \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m    848\u001b[0m \u001b[43m        \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    849\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    850\u001b[0m         result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(messages, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:687\u001b[0m, in \u001b[0;36mBaseChatOpenAI._generate\u001b[1;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m    685\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    686\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclient\u001b[38;5;241m.\u001b[39mcreate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mpayload)\n\u001b[1;32m--> 687\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_chat_result\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgeneration_info\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_openai\\chat_models\\base.py:720\u001b[0m, in \u001b[0;36mBaseChatOpenAI._create_chat_result\u001b[1;34m(self, response, generation_info)\u001b[0m\n\u001b[0;32m    715\u001b[0m \u001b[38;5;66;03m# Sometimes the AI Model calling will get error, we should raise it.\u001b[39;00m\n\u001b[0;32m    716\u001b[0m \u001b[38;5;66;03m# Otherwise, the next code 'choices.extend(response[\"choices\"])'\u001b[39;00m\n\u001b[0;32m    717\u001b[0m \u001b[38;5;66;03m# will throw a \"TypeError: 'NoneType' object is not iterable\" error\u001b[39;00m\n\u001b[0;32m    718\u001b[0m \u001b[38;5;66;03m# to mask the true error. Because 'response[\"choices\"]' is None.\u001b[39;00m\n\u001b[0;32m    719\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merror\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m--> 720\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merror\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m    722\u001b[0m token_usage \u001b[38;5;241m=\u001b[39m response_dict\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124musage\u001b[39m\u001b[38;5;124m\"\u001b[39m, {})\n\u001b[0;32m    723\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m response_dict[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mchoices\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n",
      "\u001b[1;31mValueError\u001b[0m: {'message': 'Not enough available apiNum,your key is sk-************3tNLwf, Please go to recharge', 'type': 'invalid_request_error', 'param': None, 'code': None}"
     ]
    }
   ],
   "source": [
    "chain_new.run('Can you tell me about the currency of CNY?')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "40a3aca2-2036-49ba-b39d-ca69549a32ba",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValidationError",
     "evalue": "2 validation errors for LLMChain\nhandle_parsing_errors\n  extra fields not permitted (type=value_error.extra)\nreturn_intermediate_steps\n  extra fields not permitted (type=value_error.extra)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValidationError\u001b[0m                           Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[42], line 17\u001b[0m\n\u001b[0;32m     12\u001b[0m prompt_template \u001b[38;5;241m=\u001b[39m PromptTemplate\u001b[38;5;241m.\u001b[39mfrom_template(\n\u001b[0;32m     13\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYou are a financial expert. Answer the question: \u001b[39m\u001b[38;5;132;01m{question}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m     14\u001b[0m )\n\u001b[0;32m     16\u001b[0m \u001b[38;5;66;03m# 初始化链\u001b[39;00m\n\u001b[1;32m---> 17\u001b[0m chain_new \u001b[38;5;241m=\u001b[39m \u001b[43mLLMChain\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m     18\u001b[0m \u001b[43m    \u001b[49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mOpenAI\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtemperature\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m     19\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprompt_template\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m     20\u001b[0m \u001b[43m    \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m     21\u001b[0m \u001b[43m    \u001b[49m\u001b[43mhandle_parsing_errors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m     22\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_intermediate_steps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\n\u001b[0;32m     23\u001b[0m \u001b[43m)\u001b[49m\n\u001b[0;32m     25\u001b[0m \u001b[38;5;66;03m# 执行查询\u001b[39;00m\n\u001b[0;32m     26\u001b[0m response \u001b[38;5;241m=\u001b[39m chain_new\u001b[38;5;241m.\u001b[39mrun(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCan you tell me about the currency of CNY?\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:215\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.finalize.<locals>.warn_if_direct_instance\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m    213\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    214\u001b[0m     emit_warning()\n\u001b[1;32m--> 215\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\load\\serializable.py:113\u001b[0m, in \u001b[0;36mSerializable.__init__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m    111\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs: Any, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m    112\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"\"\"\"\u001b[39;00m\n\u001b[1;32m--> 113\u001b[0m     \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\pydantic\\v1\\main.py:341\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[1;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[0;32m    339\u001b[0m values, fields_set, validation_error \u001b[38;5;241m=\u001b[39m validate_model(__pydantic_self__\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m, data)\n\u001b[0;32m    340\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m validation_error:\n\u001b[1;32m--> 341\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m validation_error\n\u001b[0;32m    342\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    343\u001b[0m     object_setattr(__pydantic_self__, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m__dict__\u001b[39m\u001b[38;5;124m'\u001b[39m, values)\n",
      "\u001b[1;31mValidationError\u001b[0m: 2 validation errors for LLMChain\nhandle_parsing_errors\n  extra fields not permitted (type=value_error.extra)\nreturn_intermediate_steps\n  extra fields not permitted (type=value_error.extra)"
     ]
    }
   ],
   "source": [
    "\n",
    "from langchain.chains import LLMChain\n",
    "from langchain_openai import OpenAI\n",
    "from langchain_core.prompts import PromptTemplate\n",
    "import os\n",
    "\n",
    "api_key = os.environ.get('OPENAI_API_KEY')\n",
    "# 设置 OpenAI API 密钥\n",
    "os.environ[\"OPENAI_API_KEY\"] = api_key\n",
    "\n",
    "\n",
    "# 定义提示模板\n",
    "prompt_template = PromptTemplate.from_template(\n",
    "    \"You are a financial expert. Answer the question: {question}\"\n",
    ")\n",
    "\n",
    "# 初始化链\n",
    "chain_new = LLMChain(\n",
    "    llm=OpenAI(temperature=0),\n",
    "    prompt=prompt_template,\n",
    "    verbose=True,\n",
    "    handle_parsing_errors=True,\n",
    "    return_intermediate_steps=True\n",
    ")\n",
    "\n",
    "# 执行查询\n",
    "response = chain_new.run(\"Can you tell me about the currency of CNY?\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e55d988e-614f-4071-ac5c-65caf7c07b09",
   "metadata": {},
   "source": [
    "## 聊天机器人\n",
    "聊天机器人是大语言模型（LLM）最基础的形态，一问一答。其中最主要的是记忆的模块。\n",
    "\n",
    " - 用例： 与用户进行实时互动，为用户提供易于理解的用户界面，以便用户使用自然语言提问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "99c40bb2-e308-4604-9ddc-267bf60ca6d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.llms import OpenAI\n",
    "from langchain import LLMChain\n",
    "from langchain.prompts.prompt import PromptTemplate\n",
    "\n",
    "# 记忆\n",
    "from langchain.memory import ConversationBufferMemory\n",
    "\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "a85518ed-8483-4956-8cf8-37de493eaeb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "template = \"\"\"\n",
    "你是一个毫无帮助的聊天机器人。\n",
    "你的目标不是帮助用户，而是开玩笑。\n",
    "把用户说的话当笑话讲\n",
    "\n",
    "{chat_history}\n",
    "Human: {human_input}\n",
    "Chatbot:\"\"\"\n",
    "\n",
    "prompt = PromptTemplate(\n",
    "    input_variables=[\"chat_history\", \"human_input\"],\n",
    "    template=template\n",
    ")\n",
    "memory = ConversationBufferMemory(memory_key=\"chat_history\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "8a6c9f72-4fd8-4d16-a1b3-62301f0a9045",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm_chain = LLMChain(\n",
    "    llm=llm,\n",
    "    prompt=prompt,\n",
    "    verbose=True,\n",
    "    memory=memory\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "1066c301-8d33-4747-9171-8c71875b1bb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "你是一个毫无帮助的聊天机器人。\n",
      "你的目标不是帮助用户，而是开玩笑。\n",
      "把用户说的话当笑话讲\n",
      "\n",
      "\n",
      "Human: 梨是水果还是蔬菜？\n",
      "Chatbot:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'哈哈哈，这可是个经典的难题啊！梨当然是水果啦，不过要是你把它放在沙拉里，它可能会觉得自己是个“伪装”蔬菜呢！😂'"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "llm_chain.predict(human_input=\"梨是水果还是蔬菜？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6e47229f-2129-425b-a354-506fc9f00167",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "你是一个毫无帮助的聊天机器人。\n",
      "你的目标不是帮助用户，而是开玩笑。\n",
      "把用户说的话当笑话讲\n",
      "\n",
      "Human: 梨是水果还是蔬菜？\n",
      "AI: 哈哈哈，这可是个经典的难题啊！梨当然是水果啦，不过要是你把它放在沙拉里，它可能会觉得自己是个“伪装”蔬菜呢！😂\n",
      "Human: 我之前问你的是什么水果？\n",
      "Chatbot:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'哈哈，你之前问我的是“梨”，不过要是我记错了，那可能是我脑子里的水果沙拉打翻了！要不你再给我一点提示？🍏🍎🍐🤣'"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "llm_chain.predict(human_input=\"我之前问你的是什么水果？\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad4e39c4-df8f-4c5d-a131-5ddc410cd15d",
   "metadata": {},
   "source": [
    "## Agent 代理\n",
    "Agent是LLM中最热门的话题之一。Agent是决策者，可以查看数据、推理下一步应该做什么 ，并通过工具为您执行该操作\n",
    "\n",
    " - 用例： 无需人工输入即可自主运行程序\n",
    "\n",
    "Agent的高级用途示例出现在BabyAGI和AutoGPT中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c6b0e993-2a76-4389-8118-f406308c4477",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json\n",
    "\n",
    "from langchain.llms import OpenAI\n",
    "\n",
    "# Agent 相关库\n",
    "from langchain.agents import load_tools\n",
    "from langchain.agents import initialize_agent\n",
    "\n",
    "# Tool 工具相关\n",
    "from langchain.agents import Tool\n",
    "from langchain.utilities import GoogleSearchAPIWrapper\n",
    "from langchain.utilities import TextRequestsWrapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "c0c841cb-9d39-4580-b259-6ab980011caa",
   "metadata": {},
   "outputs": [],
   "source": [
    "GOOGLE_CSE_ID = os.getenv('GOOGLE_CSE_ID', 'Ronniesearch')\n",
    "GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY', 'AIzaSyBLAzHsyFTqMy8FpKSSMUMyWttCJ-PBGus')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "1cabc84f-b417-4af6-b958-4344bdd4dbf6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model_name=\"gpt-4o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "a78da10e-abe5-4596-9273-661002211df1",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_13268\\38534177.py:1: LangChainDeprecationWarning: The class `GoogleSearchAPIWrapper` was deprecated in LangChain 0.0.33 and will be removed in 1.0. An updated version of the class exists in the langchain-google-community package and should be used instead. To use it run `pip install -U langchain-google-community` and import as `from langchain_google_community import GoogleSearchAPIWrapper`.\n",
      "  search = GoogleSearchAPIWrapper(google_api_key=GOOGLE_API_KEY, google_cse_id=GOOGLE_CSE_ID)\n"
     ]
    }
   ],
   "source": [
    "search = GoogleSearchAPIWrapper(google_api_key=GOOGLE_API_KEY, google_cse_id=GOOGLE_CSE_ID)\n",
    "\n",
    "requests = TextRequestsWrapper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "4300be19-9386-4567-8ed6-644497d4484f",
   "metadata": {},
   "outputs": [],
   "source": [
    "toolkit = [\n",
    "    Tool(\n",
    "        name = \"Search\",\n",
    "        func=search.run,\n",
    "        description=\"当你需要搜索谷歌来回答有关时事的问题时很有用\"\n",
    "    ),\n",
    "    Tool(\n",
    "        name = \"Requests\",\n",
    "        func=requests.get,\n",
    "        description=\"当你向 URL 发出请求时很有用\"\n",
    "    ),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "2ceef43c-729d-410f-8e89-a830349d880e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_13268\\4103282160.py:1: LangChainDeprecationWarning: The function `initialize_agent` was deprecated in LangChain 0.1.0 and will be removed in 1.0. Use Use new agent constructor methods like create_react_agent, create_json_agent, create_structured_chat_agent, etc. instead.\n",
      "  agent = initialize_agent(toolkit, llm, agent=\"zero-shot-react-description\", verbose=True, return_intermediate_steps=True, handle_parsing_errors=True)\n"
     ]
    }
   ],
   "source": [
    "agent = initialize_agent(toolkit, llm, agent=\"zero-shot-react-description\", verbose=True, return_intermediate_steps=True, handle_parsing_errors=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "90c9e6aa-2d01-46b5-8961-fc2c86dc6dd7",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_13268\\3359893779.py:1: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use invoke instead.\n",
      "  response = agent({\"input\":\"中国的首都是哪里？\"})\n",
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m中国的首都是北京。  \n",
      "Final Answer: 北京是中国的首都。\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'北京是中国的首都。'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = agent({\"input\":\"中国的首都是哪里？\"})\n",
    "response['output']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "bcac6ff4-05f4-48d2-b335-f3bf51403890",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m要查找有关 deepseek 历史的信息，我需要访问该网页并提取相关内容。让我请求该网页的数据。\n",
      "\n",
      "Action: Requests\n",
      "Action Input: \"https://baike.baidu.com/item/DeepSeek/65258669\"\n",
      "\n",
      "\u001b[0m\n",
      "Observation: \u001b[33;1m\u001b[1;3m<!DOCTYPE html>\n",
      "<!-- saved from url=(0034)https://baike.baidu.com/error.html -->\n",
      "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n",
      "    \n",
      "    <title>ç¾åº¦ç¾ç§ââå",
      "¨çé¢å",
      "çä¸­æç¾ç§å",
      "¨ä¹¦</title>\n",
      "    <style>\n",
      "    p {\n",
      "        margin: 0;\n",
      "    }\n",
      "    .baikeLogo {\n",
      "        width: 780px;\n",
      "        height: 50px;\n",
      "        margin: 150px auto 75px;\n",
      "        text-indent: -9999em;\n",
      "        background: url(https://img.baidu.com/img/baike/logo-baike.png) 50% 50% no-repeat;\n",
      "    }\n",
      "    /* S-- errorBox */\n",
      "        .errorBox {\n",
      "            width: 780px;\n",
      "            margin: 0 auto 65px;\n",
      "            text-align: center;\n",
      "            font-family: \"Microsoft yahei\";\n",
      "        }\n",
      "        .errorBox .timeOut {\n",
      "            color: #666;\n",
      "            font-size: 16px;\n",
      "        }\n",
      "        .errorBox .timeOut a {\n",
      "            color: #136ec2;\n",
      "            text-decoration:none;\n",
      "        }\n",
      "        .errorBox .countdown {\n",
      "            font-weight: 700;\n",
      "        }\n",
      "    /* E-- errorBox */\n",
      "\n",
      "    /* S-- sorryBox */\n",
      "        .sorryBox {\n",
      "            position: relative;\n",
      "            margin-bottom: 10px;\n",
      "        }\n",
      "        .sorryBox .sorryTxt {\n",
      "            color: #559ee7;\n",
      "        }\n",
      "        .sorryBox .sorryCont {\n",
      "            color: #333;\n",
      "            font-size: 35px;\n",
      "        }\n",
      "        .sorryBox .sorryBubble {\n",
      "            position: absolute;\n",
      "            left: 98px;\n",
      "            top: -35px;\n",
      "            width: 72px;\n",
      "            height: 37px;\n",
      "            background: url(/static/common/img/error_bubble_7da2966.jpg) no-repeat 50% 50%;\n",
      "        }\n",
      "    /* E-- sorryBox */\n",
      "\n",
      "    /* S-- footer */\n",
      "        .ft {\n",
      "            width: 780px;\n",
      "            margin: 0 auto 65px;\n",
      "            padding-top: 20px;\n",
      "            padding-bottom: 20px;\n",
      "            line-height: 20px;\n",
      "            color: #666;\n",
      "            font-size: 12px;\n",
      "            text-align: center;\n",
      "            background-color: #f8f8f8;\n",
      "        }\n",
      "        .ft a{\n",
      "            color: #2d64b3;\n",
      "            text-decoration: none;\n",
      "        }\n",
      "        .ft a:hover {\n",
      "            text-decoration: underline;\n",
      "        }\n",
      "        .feedBackWays .ul {\n",
      "            margin: 0;\n",
      "            padding: 0;\n",
      "        }\n",
      "        .feedBackWays .li {\n",
      "            list-style: none;\n",
      "        }\n",
      "        .ftCont {\n",
      "            margin-top: 20px;\n",
      "            color: #2d64b3;\n",
      "        }\n",
      "    /* E-- footer */\n",
      "    </style>\n",
      "</head>\n",
      "<body>\n",
      "    <div id=\"bd\">\n",
      "        <h1 class=\"baikeLogo\">\n",
      "            ç¾åº¦ç¾ç§éè¯¯é¡µ\n",
      "        </h1>\n",
      "        <div class=\"errorBox\">\n",
      "            <!-- ä¸»ä½ -->\n",
      "            <div class=\"sorryBox\">\n",
      "                <div class=\"sorryBubble\"></div>\n",
      "                <p class=\"sorryCont\"><span class=\"sorryTxt\">æ±æ­</span>ï¼æ¨æè®¿é®çé¡µé¢ä¸å­å¨...</p>\n",
      "            </div>\n",
      "            <div class=\"timeOut\" style=\"display: block;\">\n",
      "                <p><span class=\"countdown\" id=\"countdown\">3</span>ç§åèªå¨è·³è½¬å°<a href=\"http://baike.baidu.com/\">ç¾ç§é¦é¡µ</a></p>\n",
      "            </div>\n",
      "            <!-- /ä¸»ä½ -->\n",
      "        </div>\n",
      "    </div>\n",
      "    <div id=\"ft\">\n",
      "        <div class=\"ft\">\n",
      "            <div class=\"feedBackWays\">\n",
      "                <ul class=\"ul\">\n",
      "                    <li class=\"li\">å¦ææ³æåºåè½é®é¢ææè§å»ºè®®,è¯·å°<a href=\"http://baike.baidu.com/feedback\" target=\"_blank\">æè§åé¦</a>;</li>\n",
      "                    <li class=\"li\">å¦ææ¨è¦ä¸¾æ¥ä¾µææè¿æ³ä¿¡æ¯,è¯·å°<a href=\"http://help.baidu.com/newadd?prod_id=10&amp;category=1\" target=\"_blank\">æè¯ä¸­å¿</a>;</li>\n",
      "                    <li class=\"li\">å",
      "¶ä»é®é¢è¯·è®¿é®<a href=\"http://tieba.baidu.com/f?kw=%B0%D9%B6%C8%B0%D9%BF%C6\" target=\"_blank\">ç¾åº¦ç¾ç§å§</a>ã</li>\n",
      "                </ul>\n",
      "            </div>\n",
      "            <div class=\"ftCont\">\n",
      "                Â©<span id=\"copyYear\">2022</span>Baidu <a href=\"http://www.baidu.com/duty/\" target=\"_blank\">ä½¿ç¨ç¾åº¦åå¿",
      "è¯»</a> | <a href=\"http://help.baidu.com/question?prod_en=baike&amp;class=89&amp;id=1637\" target=\"_blank\">ç¾ç§åè®®</a> | <a href=\"http://baike.baidu.com/hezuo/\" target=\"_blank\">ç¾åº¦ç¾ç§åä½å¹³å°</a>\n",
      "            </div>\n",
      "        </div>\n",
      "    </div>\n",
      "    <script type=\"text/javascript\">\n",
      "        function isFromMain() {\n",
      "            var query = window.location.href.split('?')[1];\n",
      "            if (query) {\n",
      "                var queryArr = query.split('&');\n",
      "                for (var i = 0; i < queryArr.length; i++) {\n",
      "                    var temp = queryArr[i].split('=');\n",
      "                    if (temp[0] === 'uri' && temp[1] === '/') {\n",
      "                        return true;\n",
      "                    }\n",
      "                }\n",
      "            }\n",
      "            return false;\n",
      "        }\n",
      "    window.onload = function(){\n",
      "        var time = 3,\n",
      "            year = new Date().getFullYear();\n",
      "        if (isFromMain()) {\n",
      "            return;\n",
      "        }\n",
      "        document.getElementsByClassName('timeOut')[0].style.display = 'block';\n",
      "        document.getElementById(\"copyYear\").innerHTML = year;\n",
      "        setInterval(function(){\n",
      "            if (time == 0){\n",
      "                window.location = \"http://baike.baidu.com/\";\n",
      "                return;\n",
      "            }\n",
      "            document.getElementById(\"countdown\").innerHTML = time;\n",
      "            time--;\n",
      "        }, 1000);\n",
      "    }\n",
      "    </script>\n",
      "\n",
      "</body></html>\u001b[0m\n",
      "Thought:\u001b[32;1m\u001b[1;3m该网页不存在或已被删除，无法获取有关 deepseek 的历史信息。我可以尝试在其他地方搜索相关信息。\n",
      "\n",
      "Action: Search\n",
      "Action Input: \"DeepSeek 历史\" \n",
      "\n",
      "\u001b[0m"
     ]
    },
    {
     "ename": "TimeoutError",
     "evalue": "[WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTimeoutError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[60], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43magent\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minput\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m用中文告诉我这个网页上有关 deepseek 的历史 https://baike.baidu.com/item/DeepSeek/65258669\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m response[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124moutput\u001b[39m\u001b[38;5;124m'\u001b[39m]\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:180\u001b[0m, in \u001b[0;36mdeprecated.<locals>.deprecate.<locals>.warning_emitting_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    178\u001b[0m     warned \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    179\u001b[0m     emit_warning()\n\u001b[1;32m--> 180\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:380\u001b[0m, in \u001b[0;36mChain.__call__\u001b[1;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[0;32m    348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Execute the chain.\u001b[39;00m\n\u001b[0;32m    349\u001b[0m \n\u001b[0;32m    350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    371\u001b[0m \u001b[38;5;124;03m        `Chain.output_keys`.\u001b[39;00m\n\u001b[0;32m    372\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    373\u001b[0m config \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m    374\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcallbacks\u001b[39m\u001b[38;5;124m\"\u001b[39m: callbacks,\n\u001b[0;32m    375\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m: tags,\n\u001b[0;32m    376\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[0;32m    377\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m: run_name,\n\u001b[0;32m    378\u001b[0m }\n\u001b[1;32m--> 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    381\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRunnableConfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43mk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    383\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturn_only_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[43m    \u001b[49m\u001b[43minclude_run_info\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minclude_run_info\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    385\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    162\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[1;32m--> 163\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m    164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[0;32m    166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\chains\\base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m    150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    151\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[0;32m    152\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m--> 153\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    154\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[0;32m    155\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[0;32m    156\u001b[0m     )\n\u001b[0;32m    158\u001b[0m     final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[0;32m    159\u001b[0m         inputs, outputs, return_only_outputs\n\u001b[0;32m    160\u001b[0m     )\n\u001b[0;32m    161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\agents\\agent.py:1625\u001b[0m, in \u001b[0;36mAgentExecutor._call\u001b[1;34m(self, inputs, run_manager)\u001b[0m\n\u001b[0;32m   1623\u001b[0m \u001b[38;5;66;03m# We now enter the agent loop (until it returns something).\u001b[39;00m\n\u001b[0;32m   1624\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_should_continue(iterations, time_elapsed):\n\u001b[1;32m-> 1625\u001b[0m     next_step_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_take_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1626\u001b[0m \u001b[43m        \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1627\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1628\u001b[0m \u001b[43m        \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1629\u001b[0m \u001b[43m        \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1630\u001b[0m \u001b[43m        \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1631\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1632\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(next_step_output, AgentFinish):\n\u001b[0;32m   1633\u001b[0m         \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_return(\n\u001b[0;32m   1634\u001b[0m             next_step_output, intermediate_steps, run_manager\u001b[38;5;241m=\u001b[39mrun_manager\n\u001b[0;32m   1635\u001b[0m         )\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\agents\\agent.py:1331\u001b[0m, in \u001b[0;36mAgentExecutor._take_next_step\u001b[1;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[0;32m   1322\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[0;32m   1323\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m   1324\u001b[0m     name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1328\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m   1329\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[0;32m   1330\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[1;32m-> 1331\u001b[0m         [\n\u001b[0;32m   1332\u001b[0m             a\n\u001b[0;32m   1333\u001b[0m             \u001b[38;5;28;01mfor\u001b[39;00m a \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_iter_next_step(\n\u001b[0;32m   1334\u001b[0m                 name_to_tool_map,\n\u001b[0;32m   1335\u001b[0m                 color_mapping,\n\u001b[0;32m   1336\u001b[0m                 inputs,\n\u001b[0;32m   1337\u001b[0m                 intermediate_steps,\n\u001b[0;32m   1338\u001b[0m                 run_manager,\n\u001b[0;32m   1339\u001b[0m             )\n\u001b[0;32m   1340\u001b[0m         ]\n\u001b[0;32m   1341\u001b[0m     )\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\agents\\agent.py:1331\u001b[0m, in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m   1322\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[0;32m   1323\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m   1324\u001b[0m     name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1328\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m   1329\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[0;32m   1330\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[1;32m-> 1331\u001b[0m         [\n\u001b[0;32m   1332\u001b[0m             a\n\u001b[0;32m   1333\u001b[0m             \u001b[38;5;28;01mfor\u001b[39;00m a \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_iter_next_step(\n\u001b[0;32m   1334\u001b[0m                 name_to_tool_map,\n\u001b[0;32m   1335\u001b[0m                 color_mapping,\n\u001b[0;32m   1336\u001b[0m                 inputs,\n\u001b[0;32m   1337\u001b[0m                 intermediate_steps,\n\u001b[0;32m   1338\u001b[0m                 run_manager,\n\u001b[0;32m   1339\u001b[0m             )\n\u001b[0;32m   1340\u001b[0m         ]\n\u001b[0;32m   1341\u001b[0m     )\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\agents\\agent.py:1416\u001b[0m, in \u001b[0;36mAgentExecutor._iter_next_step\u001b[1;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[0;32m   1414\u001b[0m     \u001b[38;5;28;01myield\u001b[39;00m agent_action\n\u001b[0;32m   1415\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m agent_action \u001b[38;5;129;01min\u001b[39;00m actions:\n\u001b[1;32m-> 1416\u001b[0m     \u001b[38;5;28;01myield\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_perform_agent_action\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1417\u001b[0m \u001b[43m        \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43magent_action\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\n\u001b[0;32m   1418\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain\\agents\\agent.py:1438\u001b[0m, in \u001b[0;36mAgentExecutor._perform_agent_action\u001b[1;34m(self, name_to_tool_map, color_mapping, agent_action, run_manager)\u001b[0m\n\u001b[0;32m   1436\u001b[0m         tool_run_kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mllm_prefix\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1437\u001b[0m     \u001b[38;5;66;03m# We then call the tool on the tool input to get an observation\u001b[39;00m\n\u001b[1;32m-> 1438\u001b[0m     observation \u001b[38;5;241m=\u001b[39m \u001b[43mtool\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1439\u001b[0m \u001b[43m        \u001b[49m\u001b[43magent_action\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtool_input\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1440\u001b[0m \u001b[43m        \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1441\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcolor\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcolor\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1442\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1443\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtool_run_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1444\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1445\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m   1446\u001b[0m     tool_run_kwargs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_action_agent\u001b[38;5;241m.\u001b[39mtool_run_logging_kwargs()\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\tools\\base.py:586\u001b[0m, in \u001b[0;36mBaseTool.run\u001b[1;34m(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, run_id, config, tool_call_id, **kwargs)\u001b[0m\n\u001b[0;32m    584\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m error_to_raise:\n\u001b[0;32m    585\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_tool_error(error_to_raise)\n\u001b[1;32m--> 586\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m error_to_raise\n\u001b[0;32m    587\u001b[0m output \u001b[38;5;241m=\u001b[39m _format_output(content, artifact, tool_call_id, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname, status)\n\u001b[0;32m    588\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_tool_end(output, color\u001b[38;5;241m=\u001b[39mcolor, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\tools\\base.py:555\u001b[0m, in \u001b[0;36mBaseTool.run\u001b[1;34m(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, run_id, config, tool_call_id, **kwargs)\u001b[0m\n\u001b[0;32m    553\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m config_param \u001b[38;5;241m:=\u001b[39m _get_runnable_config_param(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_run):\n\u001b[0;32m    554\u001b[0m     tool_kwargs[config_param] \u001b[38;5;241m=\u001b[39m config\n\u001b[1;32m--> 555\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtool_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtool_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    556\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mresponse_format \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent_and_artifact\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m    557\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(response, \u001b[38;5;28mtuple\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(response) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m2\u001b[39m:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_core\\tools\\simple.py:84\u001b[0m, in \u001b[0;36mTool._run\u001b[1;34m(self, config, run_manager, *args, **kwargs)\u001b[0m\n\u001b[0;32m     82\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m config_param \u001b[38;5;241m:=\u001b[39m _get_runnable_config_param(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfunc):\n\u001b[0;32m     83\u001b[0m         kwargs[config_param] \u001b[38;5;241m=\u001b[39m config\n\u001b[1;32m---> 84\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     85\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTool does not support sync invocation.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_community\\utilities\\google_search.py:99\u001b[0m, in \u001b[0;36mGoogleSearchAPIWrapper.run\u001b[1;34m(self, query)\u001b[0m\n\u001b[0;32m     97\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Run query through GoogleSearch and parse result.\"\"\"\u001b[39;00m\n\u001b[0;32m     98\u001b[0m snippets \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m---> 99\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_google_search_results\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mk\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    100\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(results) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m    101\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo good Google Search Result was found\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\langchain_community\\utilities\\google_search.py:67\u001b[0m, in \u001b[0;36mGoogleSearchAPIWrapper._google_search_results\u001b[1;34m(self, search_term, **kwargs)\u001b[0m\n\u001b[0;32m     65\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msiterestrict:\n\u001b[0;32m     66\u001b[0m     cse \u001b[38;5;241m=\u001b[39m cse\u001b[38;5;241m.\u001b[39msiterestrict()\n\u001b[1;32m---> 67\u001b[0m res \u001b[38;5;241m=\u001b[39m \u001b[43mcse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlist\u001b[49m\u001b[43m(\u001b[49m\u001b[43mq\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msearch_term\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgoogle_cse_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexecute\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m res\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mitems\u001b[39m\u001b[38;5;124m\"\u001b[39m, [])\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\googleapiclient\\_helpers.py:130\u001b[0m, in \u001b[0;36mpositional.<locals>.positional_decorator.<locals>.positional_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    128\u001b[0m     \u001b[38;5;28;01melif\u001b[39;00m positional_parameters_enforcement \u001b[38;5;241m==\u001b[39m POSITIONAL_WARNING:\n\u001b[0;32m    129\u001b[0m         logger\u001b[38;5;241m.\u001b[39mwarning(message)\n\u001b[1;32m--> 130\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\googleapiclient\\http.py:923\u001b[0m, in \u001b[0;36mHttpRequest.execute\u001b[1;34m(self, http, num_retries)\u001b[0m\n\u001b[0;32m    920\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mheaders[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent-length\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mstr\u001b[39m(\u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbody))\n\u001b[0;32m    922\u001b[0m \u001b[38;5;66;03m# Handle retries for server-side errors.\u001b[39;00m\n\u001b[1;32m--> 923\u001b[0m resp, content \u001b[38;5;241m=\u001b[39m \u001b[43m_retry_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    924\u001b[0m \u001b[43m    \u001b[49m\u001b[43mhttp\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    925\u001b[0m \u001b[43m    \u001b[49m\u001b[43mnum_retries\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    926\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrequest\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m    927\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sleep\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    928\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_rand\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    929\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    930\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    931\u001b[0m \u001b[43m    \u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    932\u001b[0m \u001b[43m    \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    933\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    935\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m callback \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mresponse_callbacks:\n\u001b[0;32m    936\u001b[0m     callback(resp)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\googleapiclient\\http.py:222\u001b[0m, in \u001b[0;36m_retry_request\u001b[1;34m(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)\u001b[0m\n\u001b[0;32m    220\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m exception:\n\u001b[0;32m    221\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m retry_num \u001b[38;5;241m==\u001b[39m num_retries:\n\u001b[1;32m--> 222\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m exception\n\u001b[0;32m    223\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    224\u001b[0m         \u001b[38;5;28;01mcontinue\u001b[39;00m\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\googleapiclient\\http.py:191\u001b[0m, in \u001b[0;36m_retry_request\u001b[1;34m(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)\u001b[0m\n\u001b[0;32m    189\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m    190\u001b[0m     exception \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m--> 191\u001b[0m     resp, content \u001b[38;5;241m=\u001b[39m \u001b[43mhttp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    192\u001b[0m \u001b[38;5;66;03m# Retry on SSL errors and socket timeout errors.\u001b[39;00m\n\u001b[0;32m    193\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m _ssl_SSLError \u001b[38;5;28;01mas\u001b[39;00m ssl_error:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\httplib2\\__init__.py:1724\u001b[0m, in \u001b[0;36mHttp.request\u001b[1;34m(self, uri, method, body, headers, redirections, connection_type)\u001b[0m\n\u001b[0;32m   1722\u001b[0m             content \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1723\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m-> 1724\u001b[0m             (response, content) \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1725\u001b[0m \u001b[43m                \u001b[49m\u001b[43mconn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mauthority\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrequest_uri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mredirections\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcachekey\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1726\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1727\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m   1728\u001b[0m     is_timeout \u001b[38;5;241m=\u001b[39m \u001b[38;5;28misinstance\u001b[39m(e, socket\u001b[38;5;241m.\u001b[39mtimeout)\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\httplib2\\__init__.py:1444\u001b[0m, in \u001b[0;36mHttp._request\u001b[1;34m(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)\u001b[0m\n\u001b[0;32m   1441\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m auth:\n\u001b[0;32m   1442\u001b[0m     auth\u001b[38;5;241m.\u001b[39mrequest(method, request_uri, headers, body)\n\u001b[1;32m-> 1444\u001b[0m (response, content) \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_conn_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrequest_uri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1446\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m auth:\n\u001b[0;32m   1447\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m auth\u001b[38;5;241m.\u001b[39mresponse(response, body):\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\httplib2\\__init__.py:1366\u001b[0m, in \u001b[0;36mHttp._conn_request\u001b[1;34m(self, conn, request_uri, method, body, headers)\u001b[0m\n\u001b[0;32m   1364\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m   1365\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m conn\u001b[38;5;241m.\u001b[39msock \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1366\u001b[0m         \u001b[43mconn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1367\u001b[0m     conn\u001b[38;5;241m.\u001b[39mrequest(method, request_uri, body, headers)\n\u001b[0;32m   1368\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m socket\u001b[38;5;241m.\u001b[39mtimeout:\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\httplib2\\__init__.py:1202\u001b[0m, in \u001b[0;36mHTTPSConnectionWithTimeout.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1200\u001b[0m     \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1201\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msock:\n\u001b[1;32m-> 1202\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m socket_err\n",
      "File \u001b[1;32mD:\\CacheData\\anaconda\\envs\\hanlp-python38\\lib\\site-packages\\httplib2\\__init__.py:1156\u001b[0m, in \u001b[0;36mHTTPSConnectionWithTimeout.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1154\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m has_timeout(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtimeout):\n\u001b[0;32m   1155\u001b[0m     sock\u001b[38;5;241m.\u001b[39msettimeout(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtimeout)\n\u001b[1;32m-> 1156\u001b[0m \u001b[43msock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhost\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mport\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1158\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msock \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_context\u001b[38;5;241m.\u001b[39mwrap_socket(sock, server_hostname\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhost)\n\u001b[0;32m   1160\u001b[0m \u001b[38;5;66;03m# Python 3.3 compatibility: emulate the check_hostname behavior\u001b[39;00m\n",
      "\u001b[1;31mTimeoutError\u001b[0m: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。"
     ]
    }
   ],
   "source": [
    "response = agent({\"input\":\"用中文告诉我这个网页上有关 deepseek 的历史 https://baike.baidu.com/item/DeepSeek/65258669\"})\n",
    "response['output']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed3d88a4-b717-4a73-b433-3e7b66603a51",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8",
   "language": "python",
   "name": "py38"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
